Design mkdir and ls for a Basic File System
Company: Uber
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
# Design mkdir and ls for a Basic File System
Produce a low-level design for a basic in-memory file system that supports mkdir and ls. Identify the core entities, their relationships, path-resolution behavior, and operation flow, and describe an entity or class diagram without writing a complete runnable implementation.
### Constraints & Assumptions
- Paths are absolute and use a single root directory.
- mkdir may need a clarified policy for missing parents and existing names.
- ls must distinguish listing a directory from inspecting a file path.
### Clarifying Questions to Ask
- Should mkdir create intermediate directories?
- How should duplicate names or a file-directory name collision behave?
- What ordering should ls use, and what should it return for a file path?
```hint Make path resolution shared
Treat traversal and validation as one reusable responsibility rather than reimplementing it in every command.
```
### What a Strong Answer Covers
- File-system, directory, file, and node responsibilities.
- Parent-child ownership, name uniqueness, and path invariants.
- Stepwise mkdir and ls behavior, including error cases.
- Complexity, extensibility, and a clear class relationship diagram.
### Follow-up Questions
1. How would you add move without corrupting parent-child relationships?
2. What changes if concurrent callers may modify the same directory?
Overview: Review a clean object model and path-resolution contract for implementing mkdir and ls in a basic file system.