← Questions

Cloud storage with file versions and a trash bin

0
AnthropicCodingLast asked Apr 2024

A coding interview question asked in Anthropic's CodeSignal assessment, last asked Apr 2024. It tests object-oriented design, hash map and sorting.

Build an in-memory file store in levels, each adding operations to the last.

  1. Add a file with a size (adding an existing name stores a new version), read a file's size (its latest version), move a file with all its versions, and list the n largest files under a path prefix, by size and then name.
  2. Read a given version's size, and delete a version permanently; later version numbers shift down, and deleting the only version removes the file.
  3. Delete every file under a prefix into a trash bin, and restore every trashed file under a prefix. A name already in the trash, or already active on restore, is replaced by the incoming file.

Clarifying questions

  • Are version numbers counted from 1? What does reading a missing file or version return: None, or an error?
  • Does move fail when the destination name already exists?
  • Is the prefix a plain string prefix? For the largest files, are ties broken by name ascending?
  • Do trashed files keep all their versions?
  • What happens when a file is trashed, recreated, and trashed again before a restore?

What a strong answer covers

  • A file record holding an ordered list of version sizes, a map from name to record for active files, and a second map for the trash.
  • Add appends a version; move re-keys the record; deleting a version removes it from the list, so later numbers shift by themselves, and deleting the last version removes the file.
  • The n largest under a prefix with a scan plus a heap on (-size, name), O(F log n); mentions a sorted index or a trie when prefix queries dominate.
  • Trash and restore by prefix, applying the "incoming replaces" rule in both directions.
  • Each level tested before the next, including an invalid version number, a move onto the same name, and the empty prefix.

Follow-ups

  • Storage quotas per user.
  • Trash entries expire after a set number of days.
  • Safe for concurrent callers.
  • Store file contents, shared between versions that are identical.

Where it's asked

  • Anthropic · CodeSignal assessment · Last asked Apr 202490 min · Timed CodeSignal project in levels; the tests of one level must pass before the next one opens · No AI unless the instructions for the task allow it

What it tests

object-oriented design · hash map · sorting · simulation

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding