Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Binary Tree Level Order Traversal

Easy Acceptance 79.68% Points 20.00

You are given the root of a binary tree. Your task is to return the level order traversal of the tree

Examples
Example 1

image Input: root = [3,9,20,null,null,15,7]
Output: [[3],[9,20],[15,7]]
Explanation: The nodes are grouped according to their levels.

Example 2

image Input: root = [1]
Output: [[1]]
Explanation: The tree contains only one level.

Example 3

image Input: root = []
Output: []
Explanation: The tree is empty.

Constraints
    • 0 = Number of nodes = 105
    • -10? = Node.data = 10?
Companies
Visa
Topics
Tree Recursion Traversal + 1 more
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions