← Questions

Simplified filesystem with paths and traversal

0
AnthropicCodingLast asked May 2026

A coding interview question asked in Anthropic's CodeSignal assessment, last asked May 2026. It tests filesystems and design.

Implement a small filesystem with path lookup and directory traversal, extended in the final level with model-related behavior. The harness is strict, so edge cases around paths matter.

  • Level 1: mkdir(path) (creates parents), write(path, content), read(path), ls(path).
  • Level 2: rm(path) (recursive, never /), mv(src, dst).
  • Level 3: find(path, suffix="") and du(path).
  • Level 4: checkpoints named step-<n>.ckpt: latest_checkpoint(dir) and prune_checkpoints(dir, keep).
class FileSystem:
    def mkdir(self, path): ...
    def write(self, path, content): ...
    def read(self, path): ...
    def ls(self, path): ...

    def rm(self, path): ...
    def mv(self, src, dst): ...

    def find(self, path, suffix=""): ...
    def du(self, path): ...

    def latest_checkpoint(self, path): ...
    def prune_checkpoints(self, path, keep): ...

Clarifying questions

  • Are paths always absolute? Should //, trailing slashes, . and .. be normalized or rejected?
  • Does write create missing parent directories, and does it fail on a path that is a directory?
  • What does ls return on a file: its name, or an error? Is the listing sorted?
  • Does mv onto an existing directory move inside it or replace it, and is moving a directory into its own subtree an error?
  • For checkpoints, is step-<n> ordered by the integer n (so step-10 is after step-9), and what about names that don't match?

What a strong answer covers

  • A tree of directory nodes holding a dict of children and file nodes holding content, with one _resolve(path) helper that splits and validates every path.
  • Errors raised consistently (missing path, file where a directory is expected, removing /), since the harness checks edge cases.
  • rm and mv as relinking nodes rather than copying, with the subtree check that stops a move into itself.
  • find as a depth-first walk returning sorted full paths, and du summing content lengths recursively.
  • Checkpoints parsed with a strict pattern and compared by integer step; prune_checkpoints keeping the newest keep and removing the rest.
  • Tests: root operations, deep mkdir, moving over existing names, step-9 versus step-10, keep=0.

Follow-ups

  • Add file sizes and a quota per directory.
  • Support hard links or symlinks, and what that does to du and rm.
  • Make it safe for concurrent writers.
  • Persist the tree to disk and recover after a crash.

Where it's asked

  • Anthropic · CodeSignal assessment · Last asked May 202690 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

filesystems · design

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