← Machine Coding

Tree Navigation II

medium
Asked at
Apple
Atlassian
Microsoft
Apple, Atlassian, Microsoft

Problem statement

Tree Navigation II adds search/filter functionality to the file tree from Part I. As the user types in a search box, the tree filters to show only matching nodes — and crucially, it also shows the ancestor folders of matching nodes so the results have context, not just isolated filenames.

The algorithmic challenge is the filter function: a node should be visible if it matches the search, OR if any of its descendants match. This requires a post-order traversal — you must recurse into children first before deciding if the parent is visible.

Additionally, matching nodes should have their folders auto-expanded in the results. This tests your ability to derive display state from search state rather than managing two separate open/collapsed states.

Requirements & constraints

  • →Search input filters nodes by name (case-insensitive)
  • →Matching nodes shown with ancestor folders for context
  • →Folders with matching descendants auto-expand during search
  • →Empty state shown when no matches found
  • →Clearing search restores original tree state
  • →Match text highlighted in the node label

How to approach Tree Navigation II

The strategy an interviewer expects you to reach for.

Why This Question Exists Tree Search tests a post-order recursive filter algorithm combined with UI state management. The filter is non-trivial: a node should be visible if it matches, OR if any descendant matches. This means you cannot make visibility decisions in pre-order (top-down) — you must recurse first, then decide.

Premium

The full solution is part of HelloFrontend Pro

The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.

  • Live React sandbox pre-wired for this component
  • Time-boxed checkpoints that mirror a real 45-minute round
  • Interviewer scoring criteria and a full reference implementation
Unlock the full solution →

Already a member? Log in to open the workspace.

More Machine Coding questions

View all Machine Coding →
Machine CodingMedium

React Tic-Tac-Toe Engine

Machine CodingMedium

Performant Image Slider

Machine CodingMedium

API Search and Render Image

Machine CodingEasy

Accessible React Tabs

Machine CodingMedium

Recursive File Explorer

Machine CodingEasy

Stopwatch

Explore related prep hubs

  • All machine coding
  • Frontend machine coding guide
  • React machine coding questions
  • UI coding interview questions
  • React UI interview questions
  • Apple interview
  • Atlassian interview
  • Microsoft interview