Design hierarchical path store with create/set/get/remove
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Design a hierarchical key-value path store supporting four operations on UNIX-style absolute paths (e.g., "/a/b"). Implement:
1) create(path, value): create a new node with value; the parent path must already exist (except root "/"), and the path must not already exist.
2) set(path, value): update the value of an existing path; fail if the path does not exist.
3) get(path): retrieve the value stored at path; indicate absence if the path does not exist.
4) remove(path): delete the specified path only if it has no children; otherwise fail. Choose appropriate return types and error signaling for each method (e.g., boolean success flags, exceptions, or optionals) and document your choices. Define assumptions about valid path syntax (no trailing slash except root, segments separated by single "/", non-empty segments) and initial state (root exists and may or may not hold a value, your choice—justify it). Optimize for time/space; explain the data structures you use and the complexity of each operation. Finally, write a minimal but thorough set of unit tests that validate normal behavior and edge cases, including: creating under a missing parent, duplicate create, set on missing path, get on missing path, remove on non-leaf, remove on leaf, operations involving root, and malformed paths.
Quick Answer: This question evaluates a candidate's competency in hierarchical data structures, path parsing, API semantics, error signaling, complexity analysis, and unit testing for implementing a UNIX-style key-value path store.