PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Uber

Compute outer boundary of an N-ary tree

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in tree data structures and algorithm design, focusing on traversal and boundary extraction in ordered N-ary trees while requiring time and space complexity analysis.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Compute outer boundary of an N-ary tree

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given the root of a rooted **N-ary tree**. Each node contains: - An integer value. - An ordered list of children from left to right (0 or more children). Consider all nodes grouped by their depth (root at depth 0, its children at depth 1, etc.). For each depth `d`: - Let **L_d** be the *leftmost* node at depth `d` (the first node at that depth when scanning children from left to right). - Let **R_d** be the *rightmost* node at depth `d` (the last node at that depth when scanning children from left to right). We define the **outer boundary path** of the tree as the sequence of nodes you would "see" when walking around the outside of the tree, starting from the lowest leftmost node, going up to the root, then going down to the lowest rightmost node: 1. Starting from the **maximum depth D** down to `0`, take `L_D, L_{D-1}, ..., L_0` (bottom-left up to the root). 2. Then from depth `1` up to `D`, take `R_1, R_2, ..., R_D` (top-right down to bottom-right), **skipping** `R_d` when `R_d` is the same node as `L_d` to avoid duplicates on levels with only one node. Return the list of node values in this exact order. Assume: - Total number of nodes `n` satisfies `1 <= n <= 10^5`. - Tree height `h` can be up to `n` in the worst case. **Task**: Design an efficient algorithm to compute and return this outer boundary path. Specify the time and space complexity of your approach.

Quick Answer: This question evaluates proficiency in tree data structures and algorithm design, focusing on traversal and boundary extraction in ordered N-ary trees while requiring time and space complexity analysis.

Related Interview Questions

  • Implement stream queries and bounded-difference subarrays - Uber (medium)
  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
  • Simulate a Rank-Based Tournament - Uber (medium)
Uber logo
Uber
Oct 28, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
9
0

You are given the root of a rooted N-ary tree. Each node contains:

  • An integer value.
  • An ordered list of children from left to right (0 or more children).

Consider all nodes grouped by their depth (root at depth 0, its children at depth 1, etc.). For each depth d:

  • Let L_d be the leftmost node at depth d (the first node at that depth when scanning children from left to right).
  • Let R_d be the rightmost node at depth d (the last node at that depth when scanning children from left to right).

We define the outer boundary path of the tree as the sequence of nodes you would "see" when walking around the outside of the tree, starting from the lowest leftmost node, going up to the root, then going down to the lowest rightmost node:

  1. Starting from the maximum depth D down to 0 , take L_D, L_{D-1}, ..., L_0 (bottom-left up to the root).
  2. Then from depth 1 up to D , take R_1, R_2, ..., R_D (top-right down to bottom-right), skipping R_d when R_d is the same node as L_d to avoid duplicates on levels with only one node.

Return the list of node values in this exact order.

Assume:

  • Total number of nodes n satisfies 1 <= n <= 10^5 .
  • Tree height h can be up to n in the worst case.

Task: Design an efficient algorithm to compute and return this outer boundary path. Specify the time and space complexity of your approach.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.