Simplified filesystem with paths and traversal
I was asked this
No reports yet. Sign in to say where you were asked it.
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="")anddu(path). -
Level 4: checkpoints named
step-<n>.ckpt:latest_checkpoint(dir)andprune_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
writecreate missing parent directories, and does it fail on a path that is a directory? - What does
lsreturn on a file: its name, or an error? Is the listing sorted? - Does
mvonto 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 integern(sostep-10is afterstep-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. -
rmandmvas relinking nodes rather than copying, with the subtree check that stops a move into itself. -
findas a depth-first walk returning sorted full paths, anddusumming content lengths recursively. - Checkpoints parsed with a strict pattern and compared by integer step;
prune_checkpointskeeping the newestkeepand removing the rest. - Tests: root operations, deep
mkdir, moving over existing names,step-9versusstep-10,keep=0.
Follow-ups
- Add file sizes and a quota per directory.
- Support hard links or symlinks, and what that does to
duandrm. - 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
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to submit your code; every attempt is kept here.
