Google | Phone Screen | L5 | OCT 2024

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-11-26Added By Anonymous
Source: Link

Giving back to community:

1There is a map of cities - like a real world country's map. Some cities have roads between them, and it takes a known time to traverse each road. 2I'm in city A and have a list of my favorite cities [F1..Fn]. Give an efficient algorithm to decide which of my favorite cities I can get to the fastest. 3 4 +-----+ +-----+ +-----+ 5 8------>| A +-20-->| B +-4--->| E | 6 | +--+--+ +--^--+ +-----+ 7 | 5 2 8 | | | 9+--+--+ +--v--+ +--+--+ 10| H <-2--+ C +--2--> G | 11+--+--+ +-----+ +--+--+ 12 3 6 13 | | 14+--v--+ +--v--+ 15| F | | D | 16+-----+ +-----+


Follow Up Question #1: Another path


I realized I have some business to do in city B.


Give an algorithm that still finds the most quickly reachable favorite city, but on a path that goes through B.


Follow Up Question #2: Shortest path to end


I decided to visit B at the end of my travels (and stay there).


Give an algorithm that finds the shortest path to B that touches any of my favorite cities.

Comments