Uber [SDE 2] | DSA Round | India

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-01-22Added By Anonymous
Source: Link

Company: Uber
Role: software engineer ii
Interview Stage: Phone Screen
Location: India
Year: unknown

Original Post Content:

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