Easy
Quiz
#589 N-ary Tree Preorder Traversal
APPROACH
Given the root of an N-ary tree, return the list of node values visited in preorder (root first, then children from left to right). The tree is serialized in level-order with null separating each node's children.
Example 1:
Input: root = [1,null,3,2,4,null,5,6]
Output: [1,3,5,6,2,4]
Example 2:
Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
Output: [1,2,3,6,7,11,14,4,8,12,5,9,13,10]
1 of 4
1:00
What is the optimal approach for this problem?