In-Memory Vault File System
Updated
Problem statement
Implement an in-memory vault that stores files in directories. You are given equal-length arrays operations and paths.
Process each operation in order:
add_filestores the file at the absolute pathpaths[i]. Missing parent directories are created automatically. If that exact filename already exists in its directory, insert(x)immediately before the final extension, wherexis the smallest positive integer that produces an unused filename. The final extension begins at the last period when that period is neither the first nor the last character. A filename without such an extension receives(x)at the end.get_filestreatspaths[i]as an absolute directory path and returns the names of its immediate files in lexicographic order. A missing or empty directory returns an empty list.
Return one row for every get_files operation, in the order those queries occur. File names in a row do not include the directory prefix.
Function
runVault(operations: String[], paths: String[]) → String[][]Examples
Example 1
operations = ["add_file","add_file","add_file","get_files"]paths = ["/docs/report.txt","/docs/report.txt","/docs/image.png","/docs"]return = [["image.png","report(1).txt","report.txt"]]The second report collides with report.txt, so it becomes report(1).txt. The query lists only immediate files in sorted order.
Example 2
operations = ["add_file","add_file","get_files","get_files"]paths = ["/a/b/note","/a/c/note","/a/b","/a"]return = [["note"],[]]The first query sees the immediate file in /a/b. The vault does not return descendant files recursively, so querying /a returns an empty list.
Constraints
0 <= operations.length <= 200000.operations.length == paths.length.- Every operation is
add_fileorget_files. - Every path is absolute, uses a single
/separator between nonempty components, and contains neither.nor..directory components. - An
add_filepath contains at least one directory and one nonempty filename. - Path components contain lowercase English letters, digits, hyphens, underscores, and periods.
- The total path length across all operations is at most
1000000.
More Harvey Onsite Interview questions
- Highlight and Rank Overlapping CitationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- File System Shell CommandsONSITE INTERVIEW · Seen Nov 2026
- Spreadsheet Formula EvaluatorPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Retrieve Vectors by Cosine SimilarityONSITE INTERVIEW · Seen Nov 2026
- Evaluate an Expression MapONSITE INTERVIEW · Seen Sep 2026
- Find Duplicate Files in a FilesystemPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Highlight Matching PhrasesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEW
- Account Scheduler - Availability and AcquireStripe · ONSITE INTERVIEW
- In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEW
- In-Memory Spreadsheet ValuesRippling · PHONE SCREEN · ONSITE INTERVIEW
- Feature Flag Evaluation EngineCresta · ONSITE INTERVIEW
- Card Transaction StreamCapital One · ONSITE INTERVIEW
- Return Every Matching DecryptionDuolingo · PHONE SCREEN
- Parcel Event TrackingAirbnb · OA
- Reference-Counted Deduplicating File SystemCitadel · PHONE SCREEN
- Machine Message RouterOpenAI · PHONE SCREEN