~/problems / Stateful stores / In-memory file system

OA: Cloud file storage

medium 4 levels ~90 min Anthropic

Level 1 Files and copies

Build CloudStorage, a store of files keyed by path (like "/docs/a.txt"). Paths are plain string keys: there are no directory objects, and a path is a file only if it was added.

  • add_file(name, size) -> bool: add a file. False if a file already exists at that path.
  • copy_file(name_from, name_to) -> bool: create a copy of a file at a new path with the same size. False (changing nothing) if the source doesn't exist or something already exists at the destination.
  • get_file_size(name) -> int | None: None if there's no such file.
  • delete_file(name) -> int | None: remove the file and return its size, or None if there's no such file.
s = CloudStorage()
s.add_file("/a/x.txt", 10)          # True
s.copy_file("/a/x.txt", "/b/x.txt") # True
s.copy_file("/a/x.txt", "/b/x.txt") # False: destination exists
s.get_file_size("/b/x.txt")         # 10
s.delete_file("/a/x.txt")           # 10
s.get_file_size("/a/x.txt")         # None

Level 2 unlocks when level 1 passes.

Level 3 unlocks when level 2 passes.

Level 4 unlocks when level 3 passes.

Topic: In-memory file system. Path hierarchy as nested dicts; quotas.

0:00
Ctrl ' run · Ctrl ↵ submit
esc