Katkat

Return all file paths via DFS

NVIDIASoftware Engineer · Technical Screen

Last updated

This question evaluates understanding of tree traversal and depth-first search along with competence in handling hierarchical data structures and constructing full file paths.

You are given an in-memory representation of a file system as a tree.

Each node has:

  • name (string)
  • isFile (boolean)
  • children (list of nodes, empty for files)

The root node represents the root directory (e.g., name "/" or "root").

Write a function that returns all full paths to files in the file system. Paths should be constructed by joining directory names with /.

Notes:

  • Only files should appear in the output (not directories).
  • The order of returned paths does not matter.

Example:

  • root
  • a
  • b.txt (file)
  • c
  • d.md (file)
  • e.log (file)

Output could be:

  • root/a/b.txt
  • root/a/c/d.md
  • root/e.log

Implement the function using DFS.