← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Snowflake software engineer interview with a system design coding question about building an in-memory file system. Pretty classic OOP/design problem but there are enough edge cases to trip you up if you haven't thought it through.

Questions Asked (1)

Q1

Design an in-memory file system that supports ls (list files or directory contents), mkdir (create directories recursively), addContentToFile (create or append to a file), and readContentFromFile (return file contents as a string). All paths follow Unix-style absolute formatting.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

I started with a trie-like node structure where each node tracks whether it's a file or directory and stores children in a sorted map.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the file system as a tree of nodes where each node represents either a directory or a file, and use a hash map to store children for O(1) lookups. Implement each operation by traversing the path components from the root, creating intermediate directories as needed for mkdir and addContentToFile. For readContentFromFile, simply return the stored string content of the file node.

Pro tip: Clarify edge cases upfront—like handling trailing slashes, duplicate slashes, or paths that are just '/'—and discuss how you'd optimize for concurrent access or large files, showing you think beyond the basic implementation.

1. Clarify requirements and constraints

Ask about expected path formats, whether operations need to be thread-safe, and if there are limits on file size or number of nodes. Confirm that paths are absolute and Unix-style.

2. Design the data structure

Propose a tree where each node has a name, a flag indicating if it's a file or directory, and for directories, a map of child name to node; for files, a string content. Explain why a hash map gives O(1) average lookup per path component.

3. Implement core operations

Walk through each operation: ls splits the path and returns sorted child names if directory; mkdir recursively creates missing directories; addContentToFile creates or appends to a file; readContentFromFile returns the file's content. Emphasize path traversal and error handling.

4. Analyze complexity and trade-offs

State time complexity: O(k) per operation where k is number of path components, and space O(total nodes). Discuss trade-offs like using a trie vs. nested maps, and potential optimizations for frequent operations.

5. Test with edge cases

Mention testing paths like '/', '/a/b/c', creating files in non-existent directories, appending to existing files, and listing empty directories. Show how you'd handle errors gracefully.

Key Points to Mention

  • Tree-based data structure with directory nodes containing a map of children and file nodes containing string content
  • Path traversal by splitting on '/' and iterating through components, handling empty strings from leading/trailing slashes
  • Time complexity O(k) for k path components, space complexity O(n) for n total nodes
  • Recursive creation of intermediate directories in mkdir and addContentToFile
  • Sorting directory contents for ls to match Unix behavior
  • Thread-safety considerations and potential use of read-write locks for concurrent access

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.