Problem
Ask
Submissions

Problem: Design File System

Medium
30 min
Explore how to design a file system that allows creation of new directory-like paths and associates integer values with them. Learn to implement functions that create paths only if parent directories exist and retrieve values for existing paths, while understanding the constraints on input size and function calls.

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 class with the following functions:

  • 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 -11 if the path doesn’t exist.

Constraints:

  • The total number of calls to the two functions are \leq 10310^3.
  • 22 \leq path.length 100\leq 100
  • 11 \leq value 109\leq 10^9
Problem
Ask
Submissions

Problem: Design File System

Medium
30 min
Explore how to design a file system that allows creation of new directory-like paths and associates integer values with them. Learn to implement functions that create paths only if parent directories exist and retrieve values for existing paths, while understanding the constraints on input size and function calls.

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 class with the following functions:

  • 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 -11 if the path doesn’t exist.

Constraints:

  • The total number of calls to the two functions are \leq 10310^3.
  • 22 \leq path.length 100\leq 100
  • 11 \leq value 109\leq 10^9