Problem · Hash Table
Cloud Storage File Versioning
Learn this problemProblem statement
Implement an in-memory cloud storage system that keeps every version of an overwritten file. Process the operations in order and return one string result per operation.
File Operations
["ADD_FILE", file_name, size]: create a file and returncreated. If the name already exists, append a new version with the supplied size and returnoverwritten. Versions are numbered from1.["GET_FILE_SIZE", file_name]: return the latest version's size, or an empty string if the file does not exist.["MOVE_FILE", name_from, name_to]: move the file and all of its versions. Returnfalseif the source is missing or the destination already exists; otherwise returntrue.["GET_LARGEST_N", prefix, n]: return up tonprefix-matching files, using each file's latest size. Sort by size descending and file name ascending; format asname(size), name(size). Return an empty string when no file matches.
Version Operations
["GET_VERSION", file_name, version]: return that version's size, or an empty string if the file or version does not exist.["DELETE_VERSION", file_name, version]: permanently delete that version and returntrue. Returnfalsewhen it does not exist.- After deletion, every higher version number decreases by one. Deleting a file's only version permanently removes the file.
Function
cloudStorageFileVersioning(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD_FILE","/file-a.txt","6"],["ADD_FILE","/file-a.txt","3"],["GET_VERSION","/file-a.txt","2"],["GET_VERSION","/file-a.txt","4"],["GET_VERSION","/file-a.txt","1"],["DELETE_VERSION","/file-a.txt","1"],["GET_VERSION","/file-a.txt","1"]]return = ["created","overwritten","3","","6","true","3"]The second write creates version 2. Deleting version 1 renumbers the former version 2 to version 1.
Constraints
- All integer parameters are between
1and200.
More Anthropic problems
- Banking System, Part 1: Accounts and TransfersOA · Seen Jul 2026
- Banking System, Part 2: Top SpendersOA · Seen Jul 2026
- Banking System, Part 3: Scheduled PaymentsOA · Seen Jul 2026
- Banking System, Part 4: Merging and Balance HistoryOA · Seen Jul 2026
- Convert Stack Samples to Trace EventsPHONE SCREEN · Seen Jul 2026
- Cloud Storage SystemOA · Seen Jun 2026
- Repair the Bootloader ProgramONSITE INTERVIEW · Seen Jun 2026
- Normalize a DNS Domain NameOA · Seen May 2026