Design a Basic File System
Solve a medium-level problem for developing basic file system operations using tries.
Problem statement
Design a file system that allows you to create new text files and add content to them.
The paths in this file system are a set of strings concatenated by slashes ("/").
For example, “home” and “/home/ben” are valid paths, while an empty string and “/” are not.
Currently, this file system supports the following operations.
createFile
: This allows the users to create a file and add data to it. The function should take in the file path and the content as input, create a new file at the given path, and add text content to it. It should return false if the path file already exists or its parent path doesn’t exist.
getFileData
: This allows the users to fetch the data stored in a file. It returns the data stored in the file if the file exists and returns -1 if the path doesn’t exist.
appendContentToFile
: This allows the user to add content to a file. The function should take in the file path and the string content as input. If the file already exists, it appends the given content to the original content.
Example 1
Sample input
Get hands-on with 1400+ tech skills courses.