Design a File System with Paths
Updated
Problem statement
Build a small file system that stores a number at each path. A path looks like "/a" or "/a/b": it starts with "/" and lists names separated by "/". The parent of "/a/b" is "/a". A path with only one name, such as "/a", sits at the top and can always be created if it is new.
You are given a list of operations. Run them in order and return one result for each:
["create", path, value]: addpathand storevalueat it, then return"true". Ifpathalready exists, or its parent does not exist, change nothing and return"false".["get", path]: return the value stored atpath, or"-1"ifpathdoes not exist.["update", path, value]: ifpathexists, replace its value withvalueand return"true". Otherwise return"false".
Function
runFileSystem(operations: String[][]) → String[]Examples
Example 1
operations = [["create","/a","1"],["create","/a/b","2"],["get","/a/b"],["create","/c/d","3"],["get","/c"]]return = ["true","true","2","false","-1"]/a has one name, so it can be created. /a/b works because its parent /a exists, and get returns its value 2. /c/d fails because its parent /c was never created, and get on /c returns -1.
Example 2
operations = [["create","/home","5"],["create","/home","9"],["get","/home"],["update","/home","9"],["get","/home"],["update","/work","4"]]return = ["true","false","5","true","9","false"]The second create fails because /home already exists, so the value stays 5. update changes it to 9. The last update fails because /work does not exist.
Example 3
operations = [["create","/x","1"],["create","/x/ab","3"],["create","/x/a","2"],["get","/x/a"],["get","/x/ab"],["create","/x/c/a","4"],["get","/x/c"]]return = ["true","true","true","2","3","false","-1"]Names are matched whole. /x/ab and /x/a are two different paths, even though ab starts with a, so both are created and keep their own values. /x/c/a fails because /x/c does not exist.
Constraints
1 <= operations.length <= 104- Each operation is
["create", path, value],["get", path]or["update", path, value]. 2 <= path.length <= 100pathstarts with"/"and is one or more names separated by a single"/". Each name is one or more lowercase English letters. A path never ends with"/".valueis a whole number from1to109, written without leading zeros.
More Airbnb Phone Screen questions
- Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
- Text JustificationPHONE SCREEN · Seen Nov 2026
- Decode and Store StringsPHONE SCREEN · Seen Oct 2026
- Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
- Smallest Common RegionPHONE SCREEN · Seen Aug 2026
- Longest Chain BookingPHONE SCREEN · Seen Aug 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
- Parse Query StringPHONE SCREEN · Seen May 2026
- Pacific Atlantic Water FlowPHONE SCREEN · Seen May 2023
Similar questions at other companies
- Design File SystemGoogle · PHONE SCREENGoogle interview questions
- In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
- File System PathsCapital One · ONSITE INTERVIEWCapital One interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Design a Food Rating SystemApple · PHONE SCREENApple interview questions
- Hierarchical In-Memory File SystemClay · PHONE SCREEN
- Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
- Reference-Counted Deduplicating File SystemCitadel · PHONE SCREENCitadel interview questions