Problem · Hash Table
Cloud Storage Prefix Trash and Restore
Learn this problemProblem statement
Extend the versioned cloud storage system with a trash area. The system supports the file and version operations from Cloud Storage File Versioning, plus the operations below.
Prefix Trash Operations
["DELETE_FILES", prefix]: move every version of every active file whose name starts withprefixinto trash. Return the number of moved files as a string, or0if none match.- If trash already contains the same file name, permanently remove the older trash entry and replace it with the newly deleted file and all its versions.
["RESTORE_FILES", prefix]: move every version of every matching trash file back to active storage. Return the number of restored files as a string, or0if none match.- If active storage already contains a restored file name, permanently remove the active entry and replace it with the restored file and all its versions.
- Deleting a file's only version with
DELETE_VERSIONis permanent and never places that file in trash.
Inherited Operations
ADD_FILE, GET_FILE_SIZE, MOVE_FILE, GET_LARGEST_N, GET_VERSION, and DELETE_VERSION behave exactly as in the versioning problem.
Runner Interface
cloudStoragePrefixTrash accepts String[][] operations and returns a String[].
Function
cloudStoragePrefixTrash(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD_FILE","/dir1/dir2/a.txt","3"],["ADD_FILE","/dir1/b.txt","1"],["DELETE_FILES","/dir1"],["GET_FILE_SIZE","/dir1/dir2/a.txt"],["RESTORE_FILES","/dir1/dir2"],["GET_FILE_SIZE","/dir1/dir2/a.txt"]]return = ["created","created","2","","1","3"]Deleting prefix /dir1 moves both files to trash. Restoring the narrower prefix returns only /dir1/dir2/a.txt.
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