Uber [SDE 2] | DSA Round | India

Anonymous User
4187
Jan 22, 2025
Jan 24, 2025

Gave an interview for DSA round for Uber's SDE2 openings

Ques - 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

I came up with traversal of left most, middle and right most elements pattern. That solution failed the edge case of

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

here solution was 11,12,5, 4,7,8, 11.

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

The interviewer helped me reach this insigt. Coding this afterwards was a simple level wise BFS and you'd store the left most and right most element of each level.

Couldn't get over a segmentation error but i got the logic right.

Edit - The code is supposed to handlen-ary tree but in the example, for the ease, we visualised it with Binary Tree

Comments (9)