Panda Guru LogoPanda
Guru

Uber [SDE 2] | DSA Round | India

Round 1

Questions: Given an N-ary tree, print the nodes seen by a person when walking from bottom left to bottom right in an arc via root node.

Examples:

4 / \ 5 7 / \ / \ 12 1 a 8

Output: 12, 5, 4, 7, 8

The solution failed the edge case of:

4 / \ 5 7 / \ / \ 12 1 a 8 | 11

Here, the solution was 11, 12, 5, 4, 7, 8, 11.

Solution - The key takeaway is that you put the left most and right most element of each level after the one of the previous level. 4 -> 5 4 7 -> 12 5 4 7 8 -> 11 12 5 4 7 8 11.

Candidate's Approach

I came up with a traversal of left most, middle, and right most elements pattern. The interviewer helped me reach the insight that the solution requires storing the left most and right most elements of each level after the previous level. Coding this afterwards was a simple level-wise BFS. I encountered a segmentation error but managed to get the logic right.

Interviewer's Feedback

No feedback provided.