Asked at
Binary Tree Level Order Traversal
MediumVerifiedTreeBFSQueue~20 min
Given the root of a binary tree, return its level-order traversal: node values grouped by depth, from left to right.
A node is { val, left, right } with null children; the whole empty tree is null. The input arrives as the root node directly.
Examples
in{val:3, left:{val:9}, right:{val:20, left:{val:15}, right:{val:7}}}
out[[3], [9,20], [15,7]]
Nodes grouped by depth, left to right.
innull
out[]
An empty tree has no levels.
Constraints
- 0 ≤ number of nodes ≤ 2000
- -1000 ≤ node.val ≤ 1000
Get help
🔑
Sign in to solve
Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.