FastPrepIn-Memory Filesystem Navigation
Problems/In-Memory Filesystem Navigation

In-Memory Filesystem Navigation

Uber logoUber● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report names the commands and path features but leaves out the exact wildcard, validity, and output rules. Our version is about 88% the same as the reported question.

Build an in-memory directory tree that can change, and run a list of shell-like commands on it in order.

Each command has one of these forms:

  • pwd adds the current directory's canonical absolute path to the result. That is the full path from the root, with no . or .. in it.
  • mkdir PATH creates the last directory named in PATH. The path may be absolute or relative and may contain . and ... It has no wildcard, and its parent already exists. If the directory already exists, do nothing.
  • cd PATH moves to a new current directory once the whole path is resolved. The path may be absolute or relative. It may contain plain directory names, ., .., and *.

An absolute path starts at /. A relative path starts at the current directory. Because of *, a path can match more than one directory, so resolve it one segment at a time and keep a set of candidate directories:

  • . leaves each candidate where it is.
  • .. moves each candidate to its parent. The root stays at the root.
  • * matches any one child directory, so it covers exactly one level. Several * segments match several levels.

Every cd pattern matches at least one existing directory. If it matches several, pick the one whose canonical absolute path is lexicographically smallest. A cd changes the current directory only after the whole path is resolved, never partway through.

Return the paths printed by pwd, in command order.

Function

simulateFileSystem(commands: String[]) → String[]

Examples

Example 1

commands = ["mkdir /home","mkdir /home/alice","cd /home/alice","pwd","cd ..","pwd"]return = ["/home/alice","/home"]

After the directories are made, cd /home/alice moves there, so the first pwd gives /home/alice. Then cd .. moves to its parent, so the second pwd gives /home.

Example 2

commands = ["mkdir /teams","mkdir /teams/alpha","mkdir /teams/beta","mkdir /teams/alpha/docs","mkdir /teams/beta/docs","cd /teams/*/docs","pwd","cd .././..","pwd"]return = ["/teams/alpha/docs","/teams"]

/teams/*/docs matches both /teams/alpha/docs and /teams/beta/docs. The lexicographically smaller one is /teams/alpha/docs, so cd goes there and pwd prints it. From there, .././.. goes up a level, stays put, then goes up again, ending at /teams.

Example 3

commands = ["mkdir /a","mkdir /a/x","mkdir /a/z","mkdir /a/x/y","mkdir /a/z/y","cd /a","cd */*","pwd","cd ../../..","pwd"]return = ["/a/x/y","/"]

From /a, the relative path */* matches /a/x/y and /a/z/y. /a/x/y is lexicographically smaller, so pwd prints it. Then ../../.. takes three parent steps: to /a/x, to /a, then to the root. So the second pwd prints /.

Constraints

  • 1 <= commands.length <= 2000
  • Commands use exactly pwd, mkdir PATH, or cd PATH.
  • Directory names contain 1 to 20 lowercase English letters.
  • Every path is canonical in shape: it has no trailing slash except / and no consecutive slashes.
  • A mkdir path ends in a literal directory name, contains no *, and its parent exists.
  • Every cd path matches at least one existing directory.
  • At most 2000 directories are created, and each path has at most 200 segments.
  • The total length of all command strings is at most 200000.

More Uber Phone Screen questions

  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
  • Convex Function MinimizationPHONE SCREEN · Seen Oct 2026
  • Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
  • Merge Meeting IntervalsPHONE SCREEN · Seen Oct 2026
  • Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Find Robots by Blocker DistancesPHONE SCREEN · Seen Oct 2026
  • Sliding-Window Rate LimiterPHONE SCREEN · Seen Oct 2026
  • Count Connected IslandsPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Reference-Counted Deduplicating File SystemCitadel · PHONE SCREENCitadel interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
  • String Copy and Move LifecycleSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public String[] simulateFileSystem(String[] commands) {
        // Write your solution here
    }
}
Checking account…