FastPrepPrint All File and Folder Paths
Problems/Print All File and Folder Paths

Print All File and Folder Paths

Nutanix logoNutanix● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A candidate in a Summer 2020 Nutanix intern process got this in the second round, a 45-minute technical interview with live coding. The task was to print the full path of every file and folder. The report showed only a sample listing, and Example 1 uses those same paths.

The report does not say how the file system is given, what order to use, or any sizes. Here the file system comes as a names array and a parent array, with entry 0 as the root named "/". Each entry is listed right before everything inside it. Entries in one folder go in name order by character code. Names in one folder are all different. There are at most 200 entries. Each other name has 1 to 20 characters (lowercase letters, digits, '.', '-' or '_'). No full path is longer than 100 characters. You return the paths as a list instead of printing them.

Our version is about 80% the same as the reported question.

A file system is stored as a tree of n entries labeled 0 to n - 1. Entry 0 is the root folder: names[0] is "/" and parent[0] is -1. Every other entry i is named names[i] and sits inside the folder with label parent[i]. An entry can be a file or a folder, and you do not need to tell them apart.

The full path of the root is "/". The full path of any other entry is the names on the way from the root down to that entry, each written after a /. For example, an entry named locker inside a folder named combinations, which sits in the root, has the full path "/combinations/locker".

Return the full paths of all n entries in this order:

  • Start at the root.
  • List an entry's path, then the paths of everything inside it, before moving on to the next entry in the same folder.
  • Visit the entries of one folder in increasing order of their names. Names are compared character by character by character code, and when one name is the start of another, the shorter name comes first. For example, "docs" comes before "docs-old", "a-b" comes before "a.b", and "10" comes before "9".

Function

listAllPaths(names: String[], parent: int[]) → String[]

Examples

Example 1

names = ["/","foo","combinations","b","luggage","a","locker"]parent = [-1,0,0,1,2,1,2]return = ["/","/combinations","/combinations/locker","/combinations/luggage","/foo","/foo/a","/foo/b"]

The root folder holds foo and combinations. Folder foo holds b and a, and folder combinations holds luggage and locker.

  • Inside the root, combinations comes before foo, so everything inside /combinations is listed before /foo.
  • Inside combinations, locker comes before luggage because their second letters are o and u, and o comes first.
  • Inside foo, a comes before b, even though b has the smaller label.

Example 2

names = ["/","docs-old","a.md","docs"]parent = [-1,0,3,0]return = ["/","/docs","/docs/a.md","/docs-old"]

The root holds docs-old (entry 1) and docs (entry 3). Entry 2, a.md, is inside docs; its parent has a larger label than it does.

docs comes before docs-old because it is the start of that name. So /docs and everything inside it come first, then /docs-old.

Sorting the full paths as plain strings would give a different order: /docs-old would come before /docs/a.md, because - has a smaller character code than /.

Example 3

names = ["/"]parent = [-1]return = ["/"]

Only the root folder exists, so the only path is "/".

Constraints

  • 1 <= names.length <= 200
  • parent.length == names.length
  • names[0] is "/" and parent[0] == -1.
  • For every i >= 1, names[i] has 1 to 20 characters, and each character is a lowercase English letter, a digit, ., - or _.
  • For every i >= 1, 0 <= parent[i] <= names.length - 1, and the parent links form one tree rooted at entry 0.
  • Entries in the same folder have different names.
  • Every full path has at most 100 characters.

More Nutanix Phone Screen questions

  • Swap Adjacent Linked List NodesPHONE SCREEN · Seen Mar 2025
  • Top K Most Frequent ValuesPHONE SCREEN · Seen Mar 2025
  • Unique Triplets Summing to ZeroPHONE SCREEN · Seen Sep 2024
  • Find the Duplicate in a Read-Only ArrayPHONE SCREEN · Seen Apr 2021
  • Kth Largest Element in an ArrayPHONE SCREEN · Seen Feb 2020
  • Kth Smallest Element in a BSTPHONE SCREEN · Seen Feb 2020
  • Outline of a Binary TreePHONE SCREEN · Seen Jan 2020
  • Inorder Predecessor in a BSTPHONE SCREEN · Seen Jan 2019
  • K Largest and K Smallest ValuesPHONE SCREEN · Seen Jan 2019
  • Odd Numbers Up and BackPHONE SCREEN · Seen Jan 2019

Similar questions at other companies

  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Root-to-Leaf Paths as StringsAdobe · PHONE SCREENAdobe interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
  • Count Distinct Rooted-Tree GraftsThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Merge N-Ary Trees by KeyLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Canonical N-Ary Tree CodecApple · PHONE SCREENApple interview questions
  • Aggregate Machine TopologyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Find File Paths in a Directory TreeUber · PHONE SCREENUber interview questions

Interview reports that mention this question

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
  • Nutanix Intern Debugging Round and Interviews: 25 Experiences

Nutanix interview experiences

  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public String[] listAllPaths(String[] names, int[] parent) {
        // Write your code here.
    }
}
Checking account…