Reported September 2026
Ubertree

Find File Paths in a Directory Tree

Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Uber OA. Under 2s to a working solution.
Founder's read

The Uber OA reported in September 2026 hands you two lists of absolute paths and asks for every file whose last component matches targetName. Tree is the hinted pattern, and the statement even tells you to traverse with an explicit stack instead of recursion. That detail is the whole trap. If you blank on the build or the traversal, StealthCoder is the invisible safety net that reads the problem on screen and gives you a working solution while the proctor sees nothing. But this one is very doable if you stay calm and keep the steps small.

The problem

You are given the complete paths of every directory and file in a filesystem. Directory and file names may repeat in different locations, but every complete path is unique.
Build the directory tree and return every complete file path whose final component equals targetName. Traverse the tree with an explicit stack rather than recursion. Return matching paths in lexicographic order.

Function
findFilePaths(directoryPaths: String[], filePaths: String[], targetName: String) → String[]

Examples
Example 1
directoryPaths = ["/home","/home/docs","/tmp"]
filePaths = ["/home/docs/report.txt","/tmp/report.txt","/home/photo.jpg"]
targetName = "report.txt"
return = ["/home/docs/report.txt","/tmp/report.txt"]
The same file name appears under two different full paths.
Example 2
directoryPaths = ["/a","/a/b"]
filePaths = ["/a/b/readme.md"]
targetName = "missing.md"
return = []
No file has the requested final component.

Constraints
1 <= directoryPaths.length + filePaths.length <= 20000
Every path is canonical, absolute, nonempty, and unique.
Every file's parent directory appears in directoryPaths.
Path components contain no slash; targetName is one nonempty component.
The total number of characters across all paths is at most 200000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to not overthink it. Split each directory path on slash and insert it into a trie-like tree, where each node holds a map of children and a file flag. Insert file paths the same way. Then push the root onto a stack, pop nodes, rebuild the full path as you go by storing the path string with each stack entry, and collect any file node whose name equals targetName. Sort the results lexicographically at the end. The common pitfalls are matching directories named like the target (check the file flag), building paths with a doubled leading slash, and forgetting the sort. Honestly, you could skip the tree and just check the last component of each file path, but the statement asks for a tree and a stack, so follow it. If the live OA scrambles your head, StealthCoder is the hedge that keeps you moving.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Find File Paths in a Directory Tree cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Uber's OA.

Uber reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find File Paths in a Directory Tree FAQ

What's the trick in the Uber find file paths question?+

Build a tree of nodes keyed by path component, then walk it with an explicit stack carrying the current path string. Collect paths where a file node's name equals targetName. Sort at the end. The tree is mostly structure the statement demands, the matching logic is simple.

Do I really need to build the tree?+

The statement says to build it and use a stack, so do that. A shortcut that just checks each file path's last component gives the same answer, but it ignores the stated requirements. Follow the spec so you don't lose points on a hidden check or review.

How do I avoid recursion here?+

Push tuples of node and path string onto a list used as a stack. Pop one, and if it's a file with the target name, record its path. Otherwise push each child with its extended path. Loop until the stack is empty. This avoids deep recursion limits too.

What are the edge cases to test?+

No matches should return an empty list. A directory with the same name as targetName must not count. Names repeating under different parents should all appear. Also check the root slash handling so paths don't start with two slashes, and confirm the output is sorted lexicographically.

How do I prepare in 48 hours?+

Write a trie insert from memory, then an iterative DFS with a stack that tracks path strings. Run both examples by hand. Practice sorting string output and splitting on slash while dropping the empty first token. That covers nearly everything this problem needs.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Uber.

OA at Uber?
Invisible during screen share
Get it