Example: simple three-node tree
Input
root = TreeNode(1, TreeNode(2), TreeNode(3))
Output
[[1], [2, 3]]
Level 0 has [1]. Level 1 has [2, 3].
Full lesson preview
Return the level order traversal (breadth-first) of a binary tree as a list of level-wise node values.
Problem statement
Task
Examples
Input
root = TreeNode(1, TreeNode(2), TreeNode(3))
Output
[[1], [2, 3]]
Level 0 has [1]. Level 1 has [2, 3].
Input format
Output format
Constraints
Samples
Input
TreeNode(3, TreeNode(9), TreeNode(20, TreeNode(15), TreeNode(7)))
Output
[[3], [9, 20], [15, 7]]
Three levels: root 3, then 9 and 20, then 15 and 7.