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.
Level 1: Basic file operations (add, copy, get size)
Level 2: Find files by prefix and suffix patterns
Level 3: Multi-user system with capacity limits per user
Level 4: File compression and decompression
Input: Array of queries, each query is an array of strings
Output: Array of strings representing results for each query
Each query calls exactly one operation
This is an in-memory system - no actual file I/O
File and directory names never collide (guaranteed by problem)
Plan data structures to support all levels
The cloud storage system supports adding files, copying files, and querying file sizes.
ADD_FILE name size
Adds a new file with specified name and size (in bytes)
Returns "false" if a file with that name already exists
Copies the file at nameFrom to nameTo
Returns "true" if successful
Returns "false" if:
nameFrom doesn't exist
nameTo already exists
nameFrom points to a directory
Returns the size of the file as a string
Returns "" (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"] ]
`
Store file metadata (name, size)
Validate operations (existence checks)
Return results in specified format
Implement search functionality to find files matching prefix and suffix patterns.
Searches for files with names starting with prefix and ending with suffix
Returns formatted string: "name1(size1), name2(size2), ..."
Sort results by:
File size (descending)
File name (alphabetically) for ties
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"] ]
`
Efficient prefix and suffix matching
Sort by size (descending), then name (ascending)
Format output correctly with file names and sizes
Add multi-user support where each user has a storage capacity limit.
Adds a new user with specified storage capacity (in bytes)
Returns "true" if successful
Returns "false" if user already exists
Updates user's storage capacity limit
If new capacity is less than current usage, removes largest files (alphabetically on tie) until under limit
Returns number of removed files as string
Returns "" if user doesn't exist
User "admin" has unlimited capacity (for backward compatibility with Level 1 operations)
COPY_FILE preserves the original file's owner
If copying would exceed capacity, operation fails
queries = [ ["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) ]
Track ownership of files
Enforce capacity limits
Remove files intelligently when reducing capacity
Support compressing and decompressing files to save storage space.
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:
User doesn't exist
File doesn't exist or doesn't belong to user
File already ends with .COMPRESSED
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:
User doesn't exist
File doesn't exist or doesn't belong to user
Decompression would exceed user's capacity
Decompressed version already exists
All file sizes are guaranteed to be even (no fractional calculations)
Compressed files cannot be compressed again
COPY_FILE preserves the .COMPRESSED suffix
File names can only contain lowercase letters (so .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" ]