Google Interview Question | Onsite
Anonymous User
2967

Can anyone solve this
Given K friends location , M restaurants location and E edges. All the people are to meet at one restaurant, find the restaurant, where total travel distance from all people to that restaurant is the shortest among all restaurants. If no such resturant then return -1

Note:

It is possible that thr is no edge for friends/resturants
Numbers of edges are not fixed
All inputs can be stored in memory
Example 1:

Intput:
Friends : 1, 2
Resturants: 5
Edges: (1,3) (2,3)

Output = -1

Example 2:

Intput:
Friends : 1, 2
Resturants: 2,3
Edges: (1,3) (2,3)

Output = 3 ( as 3 is closest to both 1 an 2 friends )

Follow up : Min Time for n friends to reach m restaurants, m and n are given as bidirectional graph nodes, and unit distance needs unit time to travel for all friends.. Find out the min time in which all friends could gather at a single restaurants.

Comments (10)