Practice/Anthropic/Cloud Storage System (Online Assessment)
CodingMust
You are implementing an in-memory cloud storage system that manages files and their metadata. The system does NOT interact with the real filesystem - all operations are simulated in memory.
This is a progressive online assessment (OA) with 4 levels that unlock sequentially. Design your data structures carefully to accommodate future requirements.
The cloud storage system supports adding files, copying files, and querying file sizes.
ADD_FILE name size
"true" if successful"false" if a file with that name already existsCOPY_FILE nameFrom nameTo
Copies the file at nameFrom to nameTo
Returns "true" if successful
Returns "false" if:
nameFrom doesn't existnameTo already existsnameFrom points to a directoryGET_FILE_SIZE name
"" (empty string) if file doesn't exist` queries = [ ["ADD_FILE", "/dir1/dir2/file.txt", "10"], ["COPY_FILE", "/dir1/dir2/file.txt", "/dir1/file.txt"], ["GET_FILE_SIZE", "/dir1/file.txt"], ["GET_FILE_SIZE", "/not-existing.file"] ]
`
Implement search functionality to find files matching prefix and suffix patterns.
FIND_FILE prefix suffix
Searches for files with names starting with prefix and ending with suffix
Returns formatted string: "name1(size1), name2(size2), ..."
Sort results by:
Returns "" if no matches found
` queries = [ ["ADD_FILE", "/root/dir/another_dir/file.mp3", "10"], ["ADD_FILE", "/root/file.mp3", "5"], ["ADD_FILE", "/root/music/file.mp3", "7"], ["FIND_FILE", "/root", ".mp3"] ]
`
Add multi-user support where each user has a storage capacity limit.
ADD_USER userId capacity
"true" if successful"false" if user already existsADD_FILE_BY userId name size
Adds a file owned by the specified user
Returns remaining capacity as string if successful
Returns "" if:
UPDATE_CAPACITY userId capacity
"" if user doesn't exist"admin" has unlimited capacity (for backward compatibility with Level 1 operations)COPY_FILE preserves the original file's ownerqueries = [ ["ADD_USER", "user1", "125"], ["ADD_FILE_BY", "user1", "/dir/file.big", "50"], # Returns "75" ["ADD_FILE_BY", "user1", "/file.med", "30"], # Returns "45" ["UPDATE_CAPACITY", "user1", "50"], # Returns "2" (removes 2 files) ]
Support compressing and decompressing files to save storage space.
COMPRESS_FILE userId name
Compresses file if it belongs to the specified user
Creates new file named name.COMPRESSED with size = original size / 2
Original file is deleted
Returns remaining capacity as string if successful
Returns "" if:
.COMPRESSEDDECOMPRESS_FILE userId name
Decompresses file (must end with .COMPRESSED)
Restores original size (doubles the current size)
Removes .COMPRESSED suffix
Returns remaining capacity as string if successful
Returns "" if:
COPY_FILE preserves the .COMPRESSED suffix.COMPRESSED can only come from compression)queries = [ ["ADD_USER", "user1", "1000"], ["ADD_FILE_BY", "user1", "/dir/file.mp4", "500"], ["COMPRESS_FILE", "user1", "/dir/file.mp4"], # Returns "750" ["GET_FILE_SIZE", "/dir/file.mp4.COMPRESSED"], # Returns "250" ["GET_FILE_SIZE", "/dir/file.mp4"], # Returns "" (file removed) ["DECOMPRESS_FILE", "user1", "/dir/file.mp4.COMPRESSED"] # Returns "500" ]