Back to problems

Return all file paths via DFS

Algorithm · NVIDIA · Medium

An in-memory file system is represented as a tree. Each node contains three pieces of data: name (a string), isFile (a boolean), and children (a list of child nodes). The children list is empty for every file node. The input root represents the top-level directory; its name may be "/" or a normal directory name. Implement a function that returns all full file paths in the hierarchy. Build a path by joining node names from the root down to the file, using '/' as the…

Checking your access…