Uber India | Onsite round | Data structure and algo

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-04-25Added By Anonymous
Source: Link

Company: Uber

Interview Stage: Onsite

Location: India


Original Post Content:


For given list of folders, we need to find out what is the folder path for a given folder id from root.


Root folder id is always zero. no other folder can have zero as there folder ID. there would be multiple path from root folder.


A node can have multiple parents.

1folderList = [ 2 {id: 0, subfolders : [7,3], name: 'abc1'}, 3 {id: 0, subfolders : [9], name: 'abc2'}, 4 {id: 9, subfolders : [], name: 'abc3'}, 5 {id: 3, subfolders : [2], name: 'abc4'}, 6 {id: 2, subfolders : [], name: 'abc5'}, 7 {id: 7, subfolders : [], name: 'abc6'}, 8 {id: 8, subfolders : [], name: 'abc7'} 9]; 10for target folder = 2 it should return 11 12/abc1/abc4/abc5 13for target folder 8, it should return "" as it is not reachable from root.

What would be solution. Specially with time complexity.

Comments