Google L4 Phone Screen Round (US)

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2025-05-22Added By Anonymous
Source:Ā Link
🧭 Experience: Solved the question using LCA and path finding, but interviewer asked to optimize the traversals. āœ… Outcome: Cleared the phone screen round. šŸ’° Compensation: unknown šŸ“ Location: US šŸ¢ Company: Google šŸŽ“ Education: unknown šŸŽ Benefits: unknown šŸ“… Offer Date: unknown Given 2 numbers and an unsorted binary tree, find the path between them and return it as a string with the words "up", "right" and "left" 1 / \ 2 7 / \ 8 6 / 5 Path(root, 6, 7) -> "up, up, right" Path(root, 7, 8) -> "up, left, left" Path(root, 5, 6) -> "up, up, left" I asked the following questions: - are the node values unique? Yes - Will both nodes be always present in tree? Yes Solved it using the following approach: 1. Find LCA node between the two nodes. 2. A path function that will record L/R from LCA node to first node. 3. Same path function that will record L/R from LCA node to second node. 4. Form the answer string a. place all "up" strings for path from LCA to start node b. append the recorded path from LCA to end node Interviewer asked if I can optimise and decrease the traversals, as I was traversing the tree thrice. But couldn't think well in that interview setting. EDIT: Cleared the phone screen round. Moving Onward
Comments