Google | Onsite | Print Path
Anonymous User
748

Given list of folders, print the path of a given folder from root. If there is no path to the root folder then return an empty string. Root level folders will have 0 as id. The structure of Folder is like this:

class Folder {
   int id;
   List<Folder> subfolders;
   String name;
}

Ex:
list = [Folder(0, [7, 3], “abc”), Folder(0, [], “xyz”), Folder(8, [], “def”), Folder(7, [9], “ijk), Folder(9, [], “lmn”)]

printPath(9) = “abc” -> “ijk” -> “lmn” printPath(8) = ""

Clarification: There can be multiple root level folders. All other folders have unique ids.

Note: printPath method may be called multiple times. Design your solution taking that into account

Comments (5)