Back to course home
0% completed
N-ary Tree Level Order Traversal (hard)
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. Nodes2
,3
, and4
are the children of1
and are at level 1. Nodes5
and6
are the children of `2
- Justification: The root node
.....
.....
.....
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