In this Uber machine coding interview question, you are tasked with finding and returning the full path of a folder given its ID, starting from a "root" folder. 0
To solve this efficiently, especially for multiple queries, you should first preprocess the folder list into a parent mapping to allow for fast upward traversal.
Create a lookup table (Hash Map) where each key is a child folder ID and the value is its parent's folder ID and name. This allows you to climb "up" from the target node to the root. 3
Since IDs are unique (except for roots), if you reach a node with ID 0, you have found a valid root and can stop.
Starting at the targetID, look up its parent until you reach ID 0. Store the names in a list and reverse them at the end to get the correct order.
[0] - Uber | SSE | Hyderabad | Reject - Discuss - LeetCode [1] - Uber India | Onsite round | Data structure and algo - Discuss [2] - Uber India | Onsite round | Data structure and algo - Discuss [3] - Solve 12 coding interview problems - Uber Questions - PracHub