Design File System
Try to solve the Design File System problem.
We'll cover the following
Statement
Design a file system that allows us to create new paths and associate them with different values. A path has one or more concatenated strings of the form /
followed by one or more lowercase English letters. For example, valid paths include "/educative"
and "/educative/problems"
, while an empty string ""
and "/"
are not valid paths.
Implement the FileSystem struct with the following functions:
-
NewFileSystem(): Initializes the object of the system.
-
bool CreatePath(string path, int value): This function creates a new path and associates a value to it if possible and returns TRUE. It returns FALSE if the path already exists or if its parent path doesn’t exist.
-
int Get(string path): This function returns the value associated with the path or returns - if the path doesn’t exist.
Constraints:
- The total number of calls to the two functions are .
-
path.length
- value
Examples
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.