ExamAdda Logo

Binary Tree Level Order Traversal

Easy

Given the root of a binary tree, return its level-order traversal.

Level-order traversal means visiting the nodes level by level, from left to right.

For example:

      3    

     / \   

   9   20       

   /  \      

 15   7

 

The level-order traversal is:

[  [3],  [9,20],  [15,7] ]

Example 1

Input

root = [3,9,20,null,null,15,7]

Output

[[3],[9,20],[15,7]]

Explanation

The nodes are visited level by level:

Level 1 → 3 L

evel 2 → 9 20

Level 3 → 15 7

Example 2

Input

root = [1]

Output

[[1]]

Explanation

The tree contains only one node.

Constraints

0 <= number of nodes <= 2000
-1000 <= Node.val <= 1000

Hints:

Hint 1

Use a queue to process the tree level by level.

Hint 2

First add the root to the queue.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 12, 2026

Last updated

Aug 13, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output