Uber | Phone | Find the top k best selling food for each restaurant

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2019-06-17Added By Anonymous
Source: Link

Company: Uber

Interview Stage: Phone Screen


Original Post Content:

Question: Imagine you are UBER EAT and you have to give top k best selling food report.

Find the top k best selling food for each restaraunt.

Input#1;

restaraunt_name, food_name

"RestaurantA", "apple"

"RestaurantA", "banana"

"RestaurantA", "apple"

"RestaurantB", "coke"

"RestaurantB", "coffee"

"RestaurantB", "coffee"

"RestaurantA", "banana"

"RestaurantA", "orange"

input#2 int k

k = 2

output:

RestaurantA => ["apple", "banana"]

RestaurantB => ["coke", "coffee"]

k = 3

output:

RestaurantA => ["apple", "banana", "orange"]

RestaurantB => ["coke", "coffee"]

Comments