This question evaluates understanding of data structures and algorithms for stateful resource management, covering bookkeeping of per-user quotas, file metadata operations (copy, compress/decompress), string filtering and sorting, and efficient selection and deletion of largest elements.
Design an in-memory file system with per-user quotas and additional operations.
name
(unique string)
size
(positive int)
owner
(user id)
capacity
used
used <= capacity
.
add_user(user_id, capacity) -> bool
used = 0
.
add_file_by(user_id, name, size) -> bool
user_id
.
add_file(name, size) -> bool
admin
user with effectively unlimited capacity (or explicitly create admin with very large capacity).
copy_file(from_name, to_name) -> bool
from_name
missing,
to_name
already exists, or the owner’s capacity would be exceeded.
get_file_size(name) -> int | null
null
if missing.
get_n_largest(prefix, suffix, n) -> list<string>
name
starting with
prefix
and ending with
suffix
.
n
formatted:
"name(size)"
.
update_capacity(user_id, new_capacity) -> bool
used > new_capacity
, repeatedly delete the user’s largest files (tie-break by name asc/desc—state your tie-break clearly) until
used <= new_capacity
.
false
if user missing.
compress_file(name) -> bool
name
exists and does
not
already represent a compressed file.
name + "compress"
(or another fixed suffix; be consistent).
floor(old_size / 2)
.
used
accordingly.
decompress_file(name) -> bool
name
ends with the compression suffix.
old_size * 2
.
used
and efficient deletion of largest files (e.g., heap + lazy deletion).