Binary Tree Level Order Traversal
Medium Trees AI round
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⁴
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.
Your first AI round is free.
Watch the explanation
More Trees
- Lowest Common Ancestor of a Binary TreeAI round · Medium
- Validate Binary Search TreeAI round · Medium
- Binary Tree Vertical Order TraversalMedium
- Find Leaves of Binary TreeMedium
- Inorder Successor in BSTMedium