FastPrepIn-Memory Filesystem Commands
Problems/In-Memory Filesystem Commands

In-Memory Filesystem Commands

Perplexity AI logoPerplexity AI● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in Perplexity phone screens. The reports describe a command-driven filesystem built on a trie, built up in steps. They name the commands mkdir, touch, ls, rm, rmdir, and cd. They do not keep the exact command grammar or the edge cases. Here we set clear rules for paths, results, and invalid states. We leave out the fifth part, which was not shown.

You are building a small file system that lives in memory. You get a list of commands, operations, and run them in order.

At the start, only the root directory / exists, and the current directory is the root. A path that starts with / is absolute: it starts from the root. Any other path is relative: it starts from the current directory.

  • ["MKDIR", path] creates one empty directory. It works only when the parent directory exists and nothing is at that path yet.
  • ["TOUCH", path] creates one file. It works only when the parent directory exists and nothing is at that path yet.
  • ["LS", path] lists the names directly inside an existing directory. The names are sorted in lexicographic order and joined by commas.
  • ["RM", path] removes an existing file.
  • ["RMDIR", path] removes an existing empty directory. It fails if that directory is the root, the current directory, or an ancestor of the current directory (any directory above it).
  • ["CD", path] makes that path the current directory, if the path is an existing directory.

Return one string for each command. Every command except LS returns "true" when it works and "false" when it is refused. If LS fails, it returns "NULL". Listing an empty directory returns the empty string.

Function

runFileSystem(operations: String[][]) → String[]

Examples

Example 1

operations = [["MKDIR","/docs"],["TOUCH","/docs/readme"],["CD","/docs"],["MKDIR","drafts"],["TOUCH","drafts/plan"],["LS","/docs"],["CD","drafts"],["RM","plan"],["RMDIR","/docs"],["CD","/"],["RMDIR","/docs/drafts"],["LS","/docs"]]return = ["true","true","true","true","true","drafts,readme","true","true","false","true","true","readme"]

After CD into /docs, the relative paths drafts and drafts/plan are created inside /docs. So listing /docs gives drafts,readme. Next, the current directory moves to /docs/drafts and plan is removed. Removing /docs fails: it is not empty, and it is an ancestor of the current directory. After going back to the root, the now-empty /docs/drafts can be removed. The last listing of /docs shows only readme.

Example 2

operations = [["MKDIR","/b"],["MKDIR","/a"],["TOUCH","/a/z"],["TOUCH","/a/m"],["LS","/"],["LS","/a"],["LS","/a/z"],["CD","/missing"],["RM","/a"],["RMDIR","/"]]return = ["true","true","true","true","a,b","m,z","NULL","false","false","false"]

Listings are sorted. The root lists a,b even though /b was created first, and /a lists m,z. /a/z is a file, so LS on it returns NULL. CD fails because /missing does not exist. RM fails because /a is a directory, not a file. RMDIR fails because the root can never be removed.

Constraints

  • 1 <= operations.length <= 100000
  • Each operation has exactly one of the command shapes listed above.
  • A path is either / or an absolute or relative path in the form below. Any other path is one or more parts joined by single slashes. Each part is made of lowercase ASCII letters, digits, or underscores. A relative path does not start with a slash, and no path ends with a slash.
  • No part of a path is . or ...
  • Each path has at most 100 parts and at most 1000 characters.
  • All operations together have at most 1000000 characters.
  • All successful LS commands together list at most 200000 names.

More Perplexity AI interview questions

  • Resource Reconciler: Plan and Apply CreatesPHONE SCREEN · Seen Nov 2026
  • Agent Task Dependency TrackerPHONE SCREEN · Seen May 2026
  • LLM Provider Pool FailoverPHONE SCREEN · Seen Aug 2025
  • Feature Flags with Rules, Dependencies and ExposureONSITE INTERVIEW · Seen Nov 2026
  • Out-of-Order Bank Ledger BalancesOA · Seen Nov 2026
  • Sort Topic Names by Prefix and NumberONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • Versioned Recipe SystemThe Trade Desk · OA
  • Recipe Rating ServiceNubank · PHONE SCREEN
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • Query JSON Records with WHERE and ORDER BYGitHub · ONSITE INTERVIEW
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
  • Banking System with Top ActivityCapital One · ONSITE INTERVIEWCapital One interview questions
  • Hierarchical In-Memory File SystemClay · PHONE SCREEN

Interview reports that mention this question

  • Perplexity AI Experienced SWE Interview Loop: 1 Experience
All Perplexity AI interview questionsSee Perplexity AI hiring insights
Saved
class Solution {
    public String[] runFileSystem(String[][] operations) {
        // Write your code here
    }
}
Checking account…