Practice

Binary Tree Level Order Traversal

Module 17 · Binary Trees

Problem

Given the root of a binary tree, return the values of its nodes as level order traversal — grouped into a list of lists, one inner list per level, left to right. (LeetCode 102.)

Examples

Example 1

Inputroot = [3,9,20,null,null,15,7]Output[[3],[9,20],[15,7]]
text
      3
     / \
    9  20
       /  \
      15   7

Constraints

0 ≤ n ≤ 2000 nodes

Attempt it first

This is a direct, unmodified application of the BFS & Level-Order Traversal concept lesson — the exercise is confirming you can reproduce the level-boundary technique (snapshotting the queue's size at the start of each level) without re-deriving it. Try writing it before opening anything.