Reported August 2026
Snowflakedesign

Design In-Memory File System

Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Snowflake OA. Under 2s to a working solution.
Founder's read

Snowflake reported this one in August 2026, and the detail that matters is in the first line: the file system starts with only the root directory /. Everything else you build from operations. It's the classic design problem, a trie-style tree of directories and files, driven by an ordered array of commands. Only ls and readContentFromFile produce output rows, so you collect those and ignore the rest. If you blank on the structure during the live OA, StealthCoder is the invisible safety net that reads the problem and hands you a working solution. Most of the work is careful string handling.

The problem

Implement an in-memory file system and execute an ordered array of operations. The file system initially contains only the root directory /.
Each operation is a string array in one of these forms:
["ls", path]: if path is a file, return a one-element row containing its filename. If it is a directory, return the names of its immediate files and directories in lexicographic order.
["mkdir", path]: create every missing directory along path. Existing directories are unchanged.
["addContentToFile", filePath, content]: create the file with content when it does not exist; otherwise append content to the existing file.
["readContentFromFile", filePath]: return a one-element row containing the file's complete content.
Only ls and readContentFromFile produce output rows. Return those rows in operation order. All paths are absolute. Every operation is valid when it runs: parent directories exist where required, directory operations target directories, and file operations target files.

Function
executeFileSystem(operations: String[][]) → String[][]

Examples
Example 1
operations = [["ls","/"],["mkdir","/a/b/c"],["addContentToFile","/a/b/c/d","hello"],["ls","/"],["readContentFromFile","/a/b/c/d"]]
return = [[],["a"],["hello"]]
The first root listing is empty. Creating /a/b/c makes a visible at the root, and the final read returns the content stored in file d.
Example 2
operations = [["mkdir","/work/logs"],["addContentToFile","/work/logs/run","hello"],["addContentToFile","/work/logs/run"," world"],["mkdir","/work/cache"],["ls","/work"],["ls","/work/logs/run"],["readContentFromFile","/work/logs/run"]]
return = [["cache","logs"],["run"],["hello world"]]
The directory listing is sorted, listing a file returns only its own name, and the second write appends to the existing content.

Constraints
1 <= operations.length <= 2000
Paths are absolute, begin with /, contain no repeated slash, and have no trailing slash except for /.
Each path component contains 1 to 30 lowercase English letters.
Each content string contains at most 1000 lowercase English letters or spaces.
The total length of all operation strings is at most 200000.
No path is used as both a file and a directory.
Every operation satisfies the validity rules in the statement.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a tree of nodes. Each node holds a map of children and, for files, a content string. Split each path on / and walk from the root. For mkdir, create every missing node along the way. For addContentToFile, walk to the parent, then create the file or append to it. For ls, if the final node is a file, return a one-element row with its name. Otherwise sort the child names and return them. The pitfalls are small. Splitting / gives an empty list or an empty first token, so handle the root explicitly. An empty ls must return an empty row, as in Example 1. Keep the file name from the last path component, not the full path. With 2000 operations, sorting on each ls is fine. StealthCoder is your hedge if the live OA rattles you and the node structure won't come together.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Design In-Memory File System cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as design in memory file system. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Snowflake's OA.

Snowflake reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Design In-Memory File System FAQ

How hard is the Snowflake Design In-Memory File System problem really?+

It's medium. There's no clever algorithm, just clean modeling. If you've built a trie or a nested map before, it's maybe 40 lines. Most failures come from edge cases like the root path and empty listings, not from the core idea.

What's the trick to solving it fast?+

Use one node class with a children map and a content field. Walk the path split on /, skipping empty tokens. Every operation becomes walk, then act. Sort child names only when ls runs. That's the entire design.

What does ls return for a file versus a directory?+

For a file, return a one-element row with just its own name, not the full path. For a directory, return its immediate children in lexicographic order. An empty directory gives an empty row, which still counts as an output row.

Which operations add rows to the output?+

Only ls and readContentFromFile. mkdir and addContentToFile produce nothing. Append a row for each ls or read, in operation order, and return the whole list at the end. Mixing this up is a common bug.

How do I prepare in 48 hours?+

Write this from scratch twice with a node class and a path walker. Test the root listing, nested mkdir, and appending to a file twice. Then try a variant with deletes or moves. Knowing the shape matters more than memorizing code.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Snowflake.

OA at Snowflake?
Invisible during screen share
Get it