This question evaluates understanding of object-oriented design, stateful data structures, and resource management including user quotas, ownership semantics, and file metadata operations.
Design an in-memory cloud file system that supports files owned by users with storage quotas.
name
(string) and a
size
(positive integer).
"admin"
exists and has
infinite
capacity.
size
.
Implement a class with the following methods (exact names not required, behavior is):
add_user(user_id, capacity) -> bool
false
if the user already exists.
add_file(name, size) -> bool
admin
.
false
if the file already exists.
add_file_by(user_id, name, size) -> int | null
user_id
.
null
if:
user_id
does not exist
name
already exists
size
exceeds the user’s remaining capacity
get_file_size(name) -> int | null
null
if not found.
delete_file(name) -> int | null
null
if not found.
get_n_largest(prefix, n) -> list<string>
prefix
.
n
files formatted as:
"<name>(<size>)"
.
merge_user(user_id_1, user_id_2) -> int | null
user_id_2
into
user_id_1
.
user_id_2
become owned by
user_id_1
.
user_id_1
’s remaining capacity increases by
user_id_2
’s remaining capacity.
user_id_2
.
user_id_1
’s new remaining capacity.
null
if either user doesn’t exist or the IDs are the same.
backup_user(user_id) -> int | null
user_id
(name -> size).
null
if the user doesn’t exist.
restore_user(user_id) -> int | null
user_id
’s files from the most recent backup for that user.
user_id
.
0
.
null
.