Google L4 Phone Screen
Company: Google
Role: L4
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Was given a medium level graph question: "Broadcast and Shutdown". Given the name of a source and destination router, the max range of all routers, and a map of router names and coordinates, return a boolean indicating whether a signal sent from the source can reach the destination.
I confirmed my understanding of the question and asked a clarifying question: "Do I need to just check x and y, or do I calculate Euclidean distance?" For example, routers placed at 0,0 and 10,10 with max range should not be able to communicate. He said to ignore this calculation and gave an empty helper method getDistance, asking me to use this instead.
I discussed the optimal solution to do it in 8-10 minutes, and when he accepted the solution, I coded it out in the next 5-10 minutes, making an optimization along the way. I kept explaining the code and adjustments, but since he told me after explaining the question, "Don't mind me, I'm replying to emails," he did not seem to listen to what I was saying. After finishing the code, we discussed Time complexity which was O(N2). This is because there is a while loop doing the iterations on a queue for a BFS, and for each router I get, I find nodes in its range, which is also O(N). However, I kept a hash set of visited router names to keep track of where I'd been and avoid redundant calculations. He asked me to optimize it and hinted towards the findChildren() method, asking how we represent a graph, assuming the routers are static and won't change. All this was hinting towards an adjacency list, which is not provided. If I have to build this, then building the adjacency list itself would be O(N2) and require an additional O(N2) space, but finding children along the way helps me keep down the space complexity without increasing time complexity.
This went on for the next 20 minutes; my original solution was done in 25 minutes.
I was not happy with the interview, and received a call from the recruiter after 2 hours. She told me the feedback was not positive and I needed to work on my coding and debugging skills.
I think the interviewer was focused on the O(N2) in traversal and was not able to understand that we can make the traversal O(N), which will force us to build an adjacency list, which itself will take O(N2) time and O(N2) space.
Cool-off period: 12 months!!
Will provide my code in the comment section soon.
Please provide suggestions if I am wrong so that I don't bomb any other opportunity.