Grokking Tree Coding Patterns for Interviews
Ask Author
Back to course home

0% completed

N-ary Tree Level Order Traversal (hard)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given an n-ary tree, return a list representing the level order traversal of the nodes' values in this tree.

The input tree is serialized in an array format using level order traversal, where the children of each node are grouped together and separated by a null value.

Examples

Example 1

  • Input: root = [1, null, 2, 3, 4, null, 5, 6]
  • Expected Output: [[1], [2, 3, 4], [5, 6]]
    • Justification: The root node 1 is at level 0. Nodes 2, 3, and 4 are the children of 1 and are at level 1. Nodes 5 and 6 are the children of `2

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible