← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE interview with a tree traversal problem that looked like a standard BFS/DFS warmup until it wasn't. The outer boundary framing added enough wrinkle to keep me second-guessing my approach the whole time.

Questions Asked (1)

Q1

Given the root of an N-ary tree, compute the 'outer boundary path': starting from the deepest leftmost node, walk up to the root following leftmost nodes at each depth, then walk back down following rightmost nodes at each depth (skipping any depth where the leftmost and rightmost node are the same). Return the sequence of node values in that order.

Algorithms & Data Structures
Author's notes

My first instinct was to just do a BFS and track the first and last node at each level, which is roughly right, but I kept fumbling the dedup condition.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the definition of 'outer boundary path' and edge cases, then propose a two-phase traversal: first find the deepest leftmost node and collect the leftmost path from root to that node, then collect the rightmost path from root to the deepest rightmost node. Combine the leftmost path (excluding the root) with the reversed rightmost path (excluding the root) to form the final sequence, ensuring no duplicates when leftmost and rightmost nodes coincide at a depth.

Pro tip: Demonstrate maturity by explicitly discussing edge cases (single node, skewed tree, duplicate values) and analyzing time/space complexity. Also, mention that you would confirm the exact ordering with the interviewer before coding, as interpretations may vary.

1. Clarify and Define

Restate the problem in your own words and ask clarifying questions about edge cases, such as what to do when the tree has only one node or when leftmost and rightmost paths overlap.

2. Identify Key Paths

Determine the leftmost path from the root to the deepest leftmost node and the rightmost path from the root to the deepest rightmost node. Note that the deepest leftmost node is found by always taking the first child at each level until a leaf is reached.

3. Collect Paths

Traverse the tree to collect the leftmost path (including the deepest leftmost node but excluding the root) and the rightmost path (including the deepest rightmost node but excluding the root). Use DFS or BFS with appropriate child ordering.

4. Combine and Deduplicate

Concatenate the leftmost path with the reversed rightmost path. If the leftmost and rightmost nodes at the same depth are identical, include that node only once (typically in the leftmost path).

5. Analyze Complexity

State the time complexity (O(N) where N is the number of nodes) and space complexity (O(H) for recursion stack or O(N) for storing paths), and discuss potential optimizations.

Key Points to Mention

  • Definition of leftmost and rightmost paths in an N-ary tree
  • Handling of edge cases: single node, skewed tree, duplicate values
  • Avoiding duplicate nodes when leftmost and rightmost paths intersect
  • Time and space complexity analysis
  • Choice of traversal (DFS vs BFS) and its impact on implementation
  • Clarifying the exact output format with the interviewer

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.