PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Uber

Print directory tree with indentation

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency with representing and traversing hierarchical directory trees and producing depth-based formatted output, testing concepts such as tree traversal, recursion or iterative depth tracking, and string formatting for indentation.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Print directory tree with indentation

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a root directory of a filesystem represented as a tree. Each node is either a **directory** (can have children) or a **file** (no children). Print the directory structure starting from the root, using indentation to show depth. ### Output format - Print one node per line. - The root is printed with **no indentation**. - For each depth level below the root, prefix the name with an indentation marker (for example: `⟶ `). Repeating the marker indicates deeper nesting. Example formatting (depth shown by repeated markers): ``` dir ⟶ subdir1 ⟶ ⟶ file1.ext ⟶ ⟶ subsubdir1 ⟶ subdir2 ⟶ ⟶ subsubdir2 ⟶ ⟶ ⟶ file2.ext ``` ### Requirements / assumptions - You may assume the input is already a tree (no cycles). - The children of a directory should be printed in the order they are provided. ### Task Implement a function that, given the root node, prints (or returns as a list of strings) the directory tree in the required format.

Quick Answer: This question evaluates proficiency with representing and traversing hierarchical directory trees and producing depth-based formatted output, testing concepts such as tree traversal, recursion or iterative depth tracking, and string formatting for indentation.

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 18, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
9
0

You are given a root directory of a filesystem represented as a tree. Each node is either a directory (can have children) or a file (no children). Print the directory structure starting from the root, using indentation to show depth.

Output format

  • Print one node per line.
  • The root is printed with no indentation .
  • For each depth level below the root, prefix the name with an indentation marker (for example: ⟶ ). Repeating the marker indicates deeper nesting.

Example formatting (depth shown by repeated markers):

dir
⟶ subdir1
⟶ ⟶ file1.ext
⟶ ⟶ subsubdir1
⟶ subdir2
⟶ ⟶ subsubdir2
⟶ ⟶ ⟶ file2.ext

Requirements / assumptions

  • You may assume the input is already a tree (no cycles).
  • The children of a directory should be printed in the order they are provided.

Task

Implement a function that, given the root node, prints (or returns as a list of strings) the directory tree in the required format.

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.