Cloud Storage Prefix Trash and Restore
Reported by candidates from Anthropic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Anthropic reported this one in July 2026, and the trap is in the collision rules, not the prefix matching. It's a stateful design problem: active storage, a trash area, and versioned files that have to move between them intact. If you have an OA invite for this, expect to build on an earlier versioning problem you may not have the text of. Read the replace rules twice. StealthCoder is the safety net if you blank mid-assessment, but the logic here is learnable in one evening.
The problem
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 with prefix into trash. Return the number of moved files as a string, or 0 if 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, or 0 if 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_VERSION is 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 1 and 200.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The model is two maps keyed by file name, active and trash, each holding the full version history for that file. DELETE_FILES scans active for names starting with the prefix, then moves each entry to trash. If trash already has that name, overwrite it. The old trash entry is gone for good. RESTORE_FILES is the mirror image, and overwrites active on collision. The pitfall is mutating a map while iterating it. Collect matching keys first, then move them. Another trap is counting. Return the number of files moved, not versions, and return it as a string. Also remember DELETE_VERSION on a file's only version is permanent and never touches trash. With constraints this small, a linear scan per prefix operation is fine. If you freeze on the inherited operations, StealthCoder can read the screen and give you a working structure live, but know the two-map shape before you go in.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Cloud Storage Prefix Trash and Restore cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Anthropic's OA.
Anthropic reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Cloud Storage Prefix Trash and Restore FAQ
What's the trick in the Cloud Storage Prefix Trash problem?+
Keep two maps, active and trash, each storing a file's whole version list. Prefix delete and restore just move entries between them. The real work is the collision rule: the incoming file fully replaces the existing entry of the same name, versions and all.
Why does the example restore only one of two files?+
Deleting /dir1 trashes both files. Restoring /dir1/dir2 only matches names starting with that prefix, so only /dir1/dir2/a.txt comes back. /dir1/b.txt stays in trash. Prefix matching is applied against the trash names at restore time.
What edge case breaks a naive solution?+
Merging instead of replacing. If trash already has the same name, you must discard the older entry entirely, not combine versions. Same on restore into active. Also, deleting a file's only version with DELETE_VERSION never lands in trash, so don't route it there.
Do I count versions or files in the return value?+
Files. DELETE_FILES and RESTORE_FILES return how many distinct file names moved, as a string, or "0" if nothing matched. A file with five versions still counts as one.
How do I prepare in 48 hours?+
Implement the versioning base first: ADD_FILE, MOVE_FILE, GET_VERSION, DELETE_VERSION, GET_LARGEST_N. Then add the trash map and the two prefix operations. Write tests for collisions on both sides and for a prefix that matches nothing. Practice returning strings, since the runner expects String[].