Problem · Hash Table
Cloud Storage Compression and Decompression
Learn this problemProblem statement
Implement the compression level of an in-memory cloud storage system with user ownership and capacity limits. Return one string result per operation. Use the literal string null for an empty optional result.
Base File Operations
["ADD_FILE", name, size]: add an admin-owned file. The admin has unlimited capacity. Returntrue, orfalsewhen the name already exists.["COPY_FILE", name_from, name_to]: copy a file when the source exists and the destination does not. Preserve the source owner's identity and returntrue; otherwise returnfalse.["GET_FILE_SIZE", name]: return the file size, ornullwhen missing.
Users and Capacity
["ADD_USER", user_id, capacity]: create a unique user and returntrue, orfalsewhen the ID exists.["ADD_FILE_BY", user_id, name, size]: add an owned file without exceeding capacity. Return the user's remaining capacity, ornullon failure.["UPDATE_CAPACITY", user_id, capacity]: replace the user's capacity. If current files exceed it, remove the largest files until usage fits; break equal-size ties by file name in lexicographic order. Return the number removed, ornullfor a missing user.
Compression
["COMPRESS_FILE", user_id, name]: require an existing file owned by the user. Replace it withname + ".COMPRESSED", preserve ownership, and halve its size. File sizes supplied to this operation are guaranteed even. Return remaining capacity, ornullon failure.- The input
nametoCOMPRESS_FILEnever already ends in.COMPRESSED.ADD_FILEandADD_FILE_BYare never used to introduce compressed names.COPY_FILEpreserves the suffix. ["DECOMPRESS_FILE", user_id, name]:nameends in.COMPRESSED. Require that it exists and belongs to the user. Replace it with the suffix-free name and double its size.- Decompression fails with
nullif the uncompressed name already exists or the larger file would exceed the user's capacity. On success, return remaining capacity.
Runner Interface
cloudStorageCompression accepts String[][] operations and returns a String[].
Function
cloudStorageCompression(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD_USER","user1","1000"],["ADD_USER","user2","5000"],["ADD_FILE_BY","user1","/dir/file.mp4","500"],["COMPRESS_FILE","user2","/dir/file.mp4"],["COMPRESS_FILE","user3","/dir/file.mp4"],["COMPRESS_FILE","user1","/folder/non_existing_file"],["COMPRESS_FILE","user1","/dir/file.mp4"],["GET_FILE_SIZE","/dir/file.mp4.COMPRESSED"],["GET_FILE_SIZE","/dir/file.mp4"],["COPY_FILE","/dir/file.mp4.COMPRESSED","/file.mp4.COMPRESSED"],["ADD_FILE_BY","user1","/dir/file.mp4","500"],["DECOMPRESS_FILE","user1","/dir/file.mp4.COMPRESSED"],["UPDATE_CAPACITY","user1","2000"],["DECOMPRESS_FILE","user2","/dir/file.mp4.COMPRESSED"],["DECOMPRESS_FILE","user3","/dir/file.mp4.COMPRESSED"],["DECOMPRESS_FILE","user1","/dir/file.mp4.COMPRESSED"],["DECOMPRESS_FILE","user1","/file.mp4.COMPRESSED"]]return = ["true","true","500","null","null","null","750","250","null","true","0","null","0","null","null","null","750"]Only User 1 owns the original file. Compression reduces it from 500 to 250. The first decompression attempt lacks capacity, and a later attempt conflicts with the re-created uncompressed name. After the capacity increase, the copied compressed file can be decompressed successfully.
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