As reported: Uber SDE2 DSA round (India, January 2025): an n-ary tree; print the nodes seen by a person walking from bottom-left to bottom-right in an arc via the root. For the tree
4 → (5, 7),5 → (12, 1),7 → (a, 8)the output is12, 5, 4, 7, 8; when1has a child11, the expected output is11, 12, 5, 4, 7, 8, 11. A leftmost/middle/rightmost pattern failed that case; with the interviewer's help, a level-order BFS storing the leftmost and rightmost node of each level worked, though the code hit a runtime error. Also the coding round of an Uber Senior Security Engineer interview (Amsterdam, 2025), where the BFS took long and was not finished in time.
The tree has n nodes 0 … n − 1 with values values[i]; node 0 is the root. edges[j] = [parent, child] lists the children of each node in left-to-right order (a parent's children appear in the order they are listed). Walking an arc from the bottom-left, up to the root and down to the bottom-right, you see:
- the leftmost node of every level below the root, from the deepest level up;
- then the root;
- then the rightmost node of every level below the root, from the top level down.
A level with a single node shows it on both sides. Return the values in that order.
Example 1
values = [4,5,7,12,1,9,8], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]
Output: [12,5,4,7,8]
Example 2
values = [4,5,7,12,1,9,8,11], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6],[4,7]]
Output: [11,12,5,4,7,8,11]
Constraints: 1 ≤ n ≤ 10^5; values fit in 32 bits.
Code runner format: one JSON value per line: values, edges. Implement arcView(values, edges); the harness prints the list.