Google | Phone Screen | Senior Software Developer | Mountain View | March 2023
Anonymous User
3333

Hi Everyone,

I just gave a phone screen round for Google. I was asked one question with a follow up. Still waiting for a response. Wish me luck :)

Question - Given a directed graph of cities (where edge represents the distance between two cities), current city, and a list of favorites cities, Find the minimum distance I need to travel to reach any of my favorite cities.

Answer - I think it's a classic DFS question, I created a 'visited' Hashmap with key as city name and value as the minimum distance needed to reach that city. I traverse through all the cities and find the minimum distances for all. Return the minimum distance from the set of favourite cities. I also took care of loops in the graph. Time complexity and space complexity - O(number of cities)

Followup - Find minimum distance needed to reach any favorite city where I have to pass another specific city enroute. Just change the starting point to this enroute city.

Hope this was helpful. Good luck.

Comments (9)