Problem · Hash Table

Cloud Storage Prefix Trash and Restore

Learn this problem
HardAnthropicOA

Problem 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 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.

More Anthropic problems

drafts saved locally
public String[] cloudStoragePrefixTrash(String[][] operations) {
  // write your code here
}
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"]]
expected["created", "created", "2", "", "1", "3"]
checking account