N-ary Tree Right Side View
Problem statement
Node i has value values[i] and ordered child indices children[i]; root is 0. Return the value of the rightmost node on every level from top to bottom.
Function
naryRightSideView(values: int[], children: int[][]) → int[]Examples
Example 1
values = [1,2,3,4,5]children = [[1,2,3],[4],[],[],[]]return = [1,4,5]Indices 0, 3, and 4 are rightmost on their levels.
Constraints
- Children form one rooted tree when values is nonempty.
- At most
10^5nodes.