Practice/Google/Leetcode 1166. Design File System
CodingMust
Design and implement an in-memory directory system that stores integer values at specific path locations. Your system should support two operations:
true if the path was created successfully, or false if the operation fails.-1 if the path doesn't exist.The key challenge is implementing the constraint that a path can only be created if its immediate parent path already exists in the system.
createPath operation must fail (return false) if the immediate parent directory doesn't existcreatePath operation must fail (return false) if the path already exists in the systemget operation must return -1 for paths that haven't been created/folder/subfolder/file)1 <= path.length <= 1001 <= value <= 10^910^4 calls will be made to createPath and get combined/ is implicitly available and doesn't need to be createdExample 1:
` Operations: createPath("/documents", 100) → true createPath("/documents/reports", 200) → true get("/documents") → 100 get("/documents/reports") → 200
Explanation: We first create "/documents" which succeeds because root exists. Then we create "/documents/reports" which succeeds because "/documents" exists. Both get operations return the stored values. `
Example 2:
` Operations: createPath("/a/b/c", 1) → false createPath("/a", 2) → true createPath("/a/b", 3) → true createPath("/a/b/c", 4) → true get("/a/b/c") → 4
Explanation: The first createPath fails because "/a/b" doesn't exist. After creating "/a" and then "/a/b", we can successfully create "/a/b/c". `
Example 3:
` Operations: createPath("/home", 50) → true createPath("/home", 75) → false get("/home") → 50
Explanation: The second createPath fails because "/home" already exists. The original value remains unchanged. `