Hands-on coding example
Practice Exercise: In-Memory Filesystem
This exercise was used in Perplexity technical interviews throughout much of 2026. We’re releasing it to provide a sense of the format and style of our hands-on coding interviews. If you’d like to try the exercise in CodeSignal, please request a practice session link from your recruiter.
Part 1 of 5 (setup)
Please read the INTERVIEW_AGREEMENT.md file, which contains the general instructions and interview agreement used for Perplexity live technical rounds. In an actual interview, you would be asked to review, sign, and date this agreement in CodeSignal before beginning.
INTERVIEW_AGREEMENT.md
Reminders
- If performing this interview remotely, please share your full computer screen via Google Meet.
- This is a coding exercise with multiple parts. Each part will ask you to implement some functionality, and you may implement helper functions and/or classes if useful.
- It’s not unusual to reach the end of the interview time before finishing all parts. You should work efficiently with decent (but not necessarily production-level) code quality.
Rules on Outside Assistance
You must not use AI or other outside assistance (such as the internet or other humans) during this interview.
- Exception 1: you may refer to online language documentation.
- Exception 2: you may use Perplexity, a search engine, or another AI tool to ask questions about your language’s libraries (including to see example usage). However, do not ask the tool to produce any significant part of your answer.
If needed, your interviewer can provide further guidance about what is and is not permissible.
Perplexity Interview Agreement (Technical Round)
In connection with this opportunity to interview for a job at Perplexity, I agree to the following terms:
- I affirm that before this interview, I have not sought out or accessed any of Perplexity’s proprietary interview materials on the Internet or other sources.
- I agree to comply with the Rules on Outside Assistance.
- I agree not to cheat, deceive, or defraud.
- I agree not to record this interview, copy or take screenshots of any interview materials, or save any other records of proprietary Perplexity information.
- I agree not to disclose the interview question (and/or any details about the question) to anyone else, both during and after this interview.
- I acknowledge that violations of this Agreement are grounds for termination of my candidacy or employment, along with serious legal consequences under applicable law.
By signing my name below, I indicate that I have read and understood this entire document and I agree to its terms:
Signed: /MY FULL NAME/
Date: YEAR MONTH DATE
Introduction
Filesystems are one of the most powerful primitives for agentic AI systems. Despite (or perhaps because of) their simplicity, filesystems turn out to be an ideal abstraction for managing agent context, intermediate execution states, user memories, and more.
Perplexity’s agent products make frequent use of filesystems. However, for efficiency reasons, we sometimes prefer not to allocate a physical storage resource for each agent. In these cases, we might instead use an emulator that supports filesystem-like operations while keeping the state completely in memory.
In this exercise, you’ll implement a small in-memory filesystem emulator. You’ll focus on the filesystem’s overall structure rather than the file contents themselves.
Before you start coding, make sure to read the instructions in full (including Failure cases and Important notes). There’s a very high correlation between careful reading and success on this exercise.
Part 2 of 5
LLMs love to interact with filesystems through CLI commands. Example:
mkdir /new_dir
touch /new_dir/new_file.txt
mkdir /new_dir/child_dir
touch /new_dir/child_dir/another_file
ls /new_dir
Therefore, we’ll make CLI-style commands the primary means of interaction.
Please open src/filesystem.py and implement support for the following commands:
touch: create a new file atpath.- The output should be an empty string.
mkdir: create a new directory atpath.- The output should be an empty string.
ls: list the immediate child files and directories of the directory atpath.- The output should contain alphabetically-sorted child names, separated by spaces.
These commands are inspired by (but much simpler than) the corresponding Unix commands. If a command succeeds, return Result(True, output). If a command fails, return Result(False, "").
The path separator character is /, just like on Unix. For now, all path strings are absolute paths (meaning they begin with /).
Failure cases
A command should fail in these cases:
- The command name is unknown.
- For
touchandmkdir:- The target path already exists.
- The parent path does not exist (example:
/ais the parent path of/a/b.txt). - The parent path exists but is a file, not a directory.
- For
ls:- The target path does not exist.
- The target path is a file, not a directory.
Important notes
- Although all expected behavior is fully specified in this problem description, it may prove useful to read the unit tests to understand the expected behavior.
- You get to choose which data structures and programming patterns to use.
- The only requirement is to correctly implement the specification in a clean and reasonably efficient manner.
- We do not recommend writing all your implementation code in
execute_command. You should try to keep this function clean, or else you might go crazy as this question progresses. - Throughout this problem, you’re allowed and encouraged to write helper functions, helper classes, or any other supporting code.
- If you’re acquainted with Unix
touch, please note the following key difference: this problem expectstouchto fail on already-existing paths (whereas Unixtouchsucceeds on existing files).
Starter code
This starter code is for the Python version; starter code and problem instructions for other languages are available from your recruiter.
src/filesystem.py
from dataclasses import dataclass
@dataclass(frozen=True)
class Result:
"""
The result of executing a filesystem command.
Fields:
success: whether the command succeeded.
output: command output (or empty string if no output).
"""
success: bool
output: str
class Filesystem:
def __init__(self):
"""
Initializes an empty filesystem containing only the
root directory.
"""
# TODO: implement the constructor
pass
def execute_command(self, cmd: str, path: str) -> Result:
"""
Executes cmd against the provided path.
Args:
cmd: the command to run.
path: the filepath on which to run the command.
Returns:
A `Result` object containing the command's success status
and command output (if any).
"""
# TODO: implement this method
raise NotImplementedError
Testing
You can test your code by clicking Run Tests in CodeSignal, which runs the tests for every part revealed so far.
Once the tests pass, click Submit to proceed to the next part.
Part 3 of 5
In this part, you will add support for removing files and empty directories.
Implement these additional commands in execute_command:
rm: remove the file atpath.rmdir: remove the empty directory atpath.
As in the previous part, all paths are absolute.
If a command succeeds, return Result(True, ""). If a command fails, return Result(False, "").
Failure cases
A command should fail in these cases:
- For
rm:- The target path does not exist.
- The target path is a directory, not a file.
- For
rmdir:- The target path does not exist.
- The target path is a file, not a directory.
- The target path is a non-empty directory.
- The target path is the root directory
/.
Testing
You can test your code by clicking Run Tests in CodeSignal, which runs the tests for every part revealed so far.
Once the tests pass, click Submit to proceed to the next part.
Part 4 of 5
In this part, you will implement support for relative paths and a current working directory.
Command for changing current working directory
Implement this additional command in execute_command:
cd: change the current working directory topath.
cd should fail if the path does not exist or is a file.
If cd succeeds, return Result(True, ""). If cd fails, return Result(False, "") and leave the current working directory unchanged.
The current working directory should initially be / (the filesystem’s root directory).
Support for relative paths
In addition, all commands should now accept both absolute and relative paths.
Relative paths should be resolved against the current working directory. Support these common path components:
.means the current directory...means the parent directory.- Per Unix convention, the parent of
/(the filesystem’s root directory) is itself.
- Per Unix convention, the parent of
- Any path that does not begin with
/should be interpreted relative to the current working directory. - Any path that begins with
/should be interpreted relative to the filesystem’s root directory.
For example, if the current working directory is /home/alice, then:
touch notes.txtcreates/home/alice/notes.txt.mkdir ../bobcreates/home/bob.mkdir ../../carolcreates/carol.mkdir ../../../doncreates/don.ls .lists/home/alice.ls /homelists/home.ls /home/..lists/.
Note that rmdir should fail for any path that resolves to the current working directory.
Testing
You can test your code by clicking Run Tests in CodeSignal, which runs the tests for every part revealed so far.
Once the tests pass, click Submit to proceed to the next part.
Part 5 of 5
In this part, you will add support for recursively rendering part of the filesystem tree.
Implement support for this additional command:
find: return a string that comprehensively captures all files and directories within the directory tree rooted atpath.
Please choose an LLM-friendly output format that clearly represents the filetree, and consider why your chosen format is easy for an LLM to interpret. If you are familiar with the Unix find command, please note that you do not need to match its exact output format.
find should support both absolute and relative paths. If the path does not exist or is a file, return Result(False, ""). Naturally, calling find on / should return a rendering of the entire filesystem.
Testing
You can test your code by clicking Run Tests in CodeSignal, which runs the tests for every part revealed so far. The tests check that the expected files and directories appear in the output, so you will also want to inspect the actual string to make sure that it looks as expected.
What to focus on
This exercise is designed to reveal practical engineering judgment. As you work, prioritize:
- Choosing clean abstractions and data structures for representing the filesystem hierarchy rather than putting everything in
execute_command. - Handling path normalization and edge cases cleanly as new commands and relative paths are introduced.
- Preserving the behavior from earlier parts as the design evolves.
- Writing code that is easy to explain, test, and extend.
It is not unusual to reach the end of a live interview before completing every part. Aim for precise, working code rather than rushing through the entire exercise.
Refer to our hands-on coding interview guide for more tips and guidance.