Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Binary Tree Level Order Traversal

Medium
treebinary-treebfs

Return the level order traversal of a binary tree — node values level by level, left to right.

Input: one line — the tree in level order (with nulls). Output: one line per level, values space-separated (nothing for an empty tree).

Example 1
Input:
3 9 20 null null 15 7
Output:
3
9 20
15 7
Example 2
Input:
1
Output:
1

Constraints

  • 0 ≤ nodes ≤ 2000
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.