Binary Tree Level Order Traversal
Medium Trees
root is the root of a binary tree with at least one node.
The tree's levels group its nodes by their depth: the root alone is the first level, its children make the second, their children the third, and so on down to the deepest nodes.
Return the values of the nodes level by level, from the root's level down, each level as a list of its values read from left to right.
Example 1
4, the root, is the first level alone. Its children 9 and 1 make the second. Below them, 7, 3 and 8 make the third, read from left to right: 7 hangs to the right of 9, and 3 and 8 under 1. 2, under 7, is the last level.
Example 2
Example 3
Constraints
1 ≤ number of nodes ≤ 10⁵-10⁴ ≤ node.val ≤ 10⁴
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Trees
- Lowest Common Ancestor of a Binary TreeAI round · Medium
- Validate Binary Search TreeAI round · Medium
- Symmetric TreeAI round · Easy
- Binary Tree Vertical Order TraversalMedium
- Find Leaves of Binary TreeMedium