PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Simulate views on an n-ary tree

Last updated: May 5, 2026

Quick Overview

This question evaluates proficiency in tree traversal and algorithm design for ordered n-ary trees, focusing on identifying visible boundary nodes given child ordering and reasoning about time and space complexity.

  • Medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Simulate views on an n-ary tree

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given a rooted, ordered n-ary tree (each node has a value and an ordered list of children), simulate an observer who starts at the bottom-left, moves upward to the root level while looking to the right, then continues downward to the bottom-right while looking to the left. At each depth during the upward phase, output the leftmost visible node (the first node encountered at that depth when scanning children left-to-right). During the downward phase, at each depth output the rightmost visible node (the first node encountered at that depth when scanning children right-to-left). Concatenate these into one sequence without duplicates (do not repeat the root if already output). Design an algorithm to compute this sequence for any n-ary tree, analyze time and space complexity, provide pseudocode, and discuss edge cases such as a single-node tree and highly unbalanced trees.

Quick Answer: This question evaluates proficiency in tree traversal and algorithm design for ordered n-ary trees, focusing on identifying visible boundary nodes given child ordering and reasoning about time and space complexity.

Related Interview Questions

  • Thread-Safe Token-Bucket Rate Limiter - Uber
  • Quadtree for 2D Geospatial Points - Uber
  • Group Anagrams - Uber
  • Deep Equality of Two Records - Uber (medium)
  • Shortest Path in a Grid with Blocked Cells - Uber (medium)
|Home/Coding & Algorithms/Uber

Simulate views on an n-ary tree

Uber logo
Uber
Sep 6, 2025, 12:00 AM
MediumSoftware EngineerTechnical ScreenCoding & Algorithms
4
0

Given a rooted, ordered n-ary tree (each node has a value and an ordered list of children), simulate an observer who starts at the bottom-left, moves upward to the root level while looking to the right, then continues downward to the bottom-right while looking to the left. At each depth during the upward phase, output the leftmost visible node (the first node encountered at that depth when scanning children left-to-right). During the downward phase, at each depth output the rightmost visible node (the first node encountered at that depth when scanning children right-to-left). Concatenate these into one sequence without duplicates (do not repeat the root if already output). Design an algorithm to compute this sequence for any n-ary tree, analyze time and space complexity, provide pseudocode, and discuss edge cases such as a single-node tree and highly unbalanced trees.

Submit Your Answer to Earn 20XP

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 8,000+ 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
  • AI Coding 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.