
Implement an in-memory cloud storage service that supports multiple users, per-user storage quotas, changing quotas with eviction, and file compression/decompression.
You are given a list of queries. Each query is an array of strings where the first element is the operation name. Return an array of strings—one result per query.
userId
capacity
(maximum total size of that user’s files)
fileName
(string)
size
(positive integer)
All operations are scoped to a user unless stated otherwise.
ADD_USER userId capacityCreate a new user.
userId
already exists: return
"false"
.
"true"
.
ADD_FILE userId fileName sizeAdd a new file for a user.
"false"
.
"false"
.
"false"
.
"true"
.
GET_FILE_SIZE userId fileNameReturn the size of a file.
""
(empty string).
UPDATE_CAPACITY userId newCapacityUpdate a user’s capacity. If after the update the user is over capacity, you must delete existing files until the total used size is within capacity.
Eviction rule:
fileName
to make the behavior deterministic.
newCapacity
.
Return:
"-1"
.
"0"
.)
COMPRESS_FILE userId fileNameCompress an existing file.
fileName
to
fileName + ".compressed"
.
size / 2
using
integer division
.
Rules:
"false"
.
fileName
does not exist: return
"false"
.
fileName
already ends with
.compressed
: return
"false"
.
fileName + ".compressed"
already exists for that user: return
"false"
.
"true"
.
Note: Compression reduces used space, so it will never violate capacity.
DECOMPRESS_FILE userId compressedNameDecompress an existing compressed file.
compressedName
to the original name by removing the
.compressed
suffix.
size * 2
.
Rules:
"false"
.
compressedName
does not exist: return
"false"
.
compressedName
does
not
end with
.compressed
: return
"false"
.
originalName
be
compressedName
with the final
.compressed
removed. If a file named
originalName
already exists: return
"false"
.
"false"
(and do not change anything).
"true"
.
queries
, a list of string arrays.
userId
and
fileName
are non-empty strings.
Queries:
["ADD_USER","alice","10"]
→
"true"
["ADD_FILE","alice","a.txt","6"]
→
"true"
["COMPRESS_FILE","alice","a.txt"]
→
"true"
(now
a.txt.compressed
size 3)
["DECOMPRESS_FILE","alice","a.txt.compressed"]
→
"true"
(back to size 6)
["UPDATE_CAPACITY","alice","4"]
→ must delete largest files until used
; return number deleted.