Description
Design a file system that allows you to create new paths and associate values with them. createPath(path, value) creates a new path if valid. get(path) returns the value.
Examples
Input:
createPath("/a", 1), get("/a")Output:
1Explanation:
Path /a created with value 1.
Input:
createPath("a", 1), get("a")Output:
0Explanation:
Edge case with a single character.
Input:
createPath("/documents/projects", 42), createPath("/documents/projects/web", 100), get("/documents/projects"), get("/documents/projects/web"), get("/documents")Output:
false, false, -1, -1, -1Explanation:
Creating nested paths fails because parent directories must exist first. Since /documents doesn't exist, creating /documents/projects fails. Similarly, /documents/projects/web fails. All get operations return -1 for non-existent paths.
Constraints
- •
2 ≤ path.length ≤ 100 - •
1 ≤ value ≤ 10⁹