Level 1 Files and sizes
Build VersionedStorage, a cloud store of files. A file has a name, which is a path-like string such as "/docs/plan.txt", and a size, a positive integer. Names are plain string keys: there are no folder objects, and a name is a file only if it was added.
add_file(name, size) -> bool: add a new file. ReturnFalse, changing nothing, if a file with that name already exists.overwrite_file(name, size) -> int | None: give an existing file a new size and return its previous size. ReturnNoneif there's no such file.get_file_size(name) -> int | None: the file's size, orNoneif there's no such file.delete_file(name) -> int | None: remove the file and return its size, orNoneif there's no such file.list_files(prefix) -> list[str]: every file whose name starts withprefix, written as"<name>(<size>)"and sorted by name in string order. An empty prefix matches every file.
s = VersionedStorage()
s.add_file("/docs/a.txt", 10) # True
s.add_file("/docs/a.txt", 99) # False: the name is taken
s.add_file("/docs/b.txt", 5) # True
s.add_file("/img/c.png", 70) # True
s.overwrite_file("/docs/a.txt", 12) # 10: the previous size
s.overwrite_file("/nope", 1) # None
s.get_file_size("/docs/a.txt") # 12
s.list_files("/docs/") # ["/docs/a.txt(12)", "/docs/b.txt(5)"]
s.delete_file("/img/c.png") # 70
s.list_files("") # ["/docs/a.txt(12)", "/docs/b.txt(5)"]
Constraints: up to 10^5 calls, sizes up to 10^9, names up to 30 characters.
Later levels keep every version of a file, add a trash, and add users with backups. Each level unlocks when the previous one passes.
⭐ Bonus: a speed test with 20,000 files and 20,000 prefix queries earns a star if a query doesn't look at every file.