Grokking Tree Coding Patterns for Interviews
0% completed
Solution: N-ary Tree Level Order Traversal
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
1is at level 0. Nodes2,3, and4are the children of1and are at level 1. Nodes5and6are the children of `2
- Justification: The root node
.....
.....
.....
Like the course? Get enrolled and start learning!
Vladimir Surcov
· a year ago
Task tell us to contstruct tree from array with null but in test data we get tree already
Show 1 reply
Aleksa Rajkovic
· 4 months ago
Please consider updating it so it supports both serialization and deserialization of N-Ary Tree Level Order.