3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* # BFS Level Order (Practice 4350): Walkthrough Interviewers love bfs level order because it checks whether you can state the invariant before coding. Here is a compact rehearsal note. ## Approach Queue nodes; process level by level collecting values. ```python from collections import deque def level_order(root): if not root: return [] q, out = deque([root]), [] while q: level = [] for _ in range(len(q)): n = q.popleft(); level.append(n.val) if n.left: q.append(n.left) if n.right: q.append(n.right) out.append(level) return out ``` ## Complexity Linear in the dominant input size for the scan; heap/tree variants add a log factor. ## Interview pitfalls State the invariant out loud, name the complexity, then code. Skipping the invariant is the usual fail mode. ## Practicing out loud Narrate the approach, complexity and one edge case in under a minute. Disclosure: I work on Linkjob AI, a real-time interview assistant. If you want live practice help, see [Linkjob AI](https://www.linkjob.ai/). */ echo 'ok';
Output for 8.2.0 - 8.2.35, 8.3.0 - 8.3.36, 8.4.1 - 8.4.27, 8.5.0 - 8.5.12
ok

preferences:
18.51 ms | 1159 KiB | 6 Q