Uber phone screen - Combinations of dishes from the menu

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

Company: Uber
Role: Software Engineer
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

Position: Software Engineer

Given a menu card and an amount, how many dishes can I afford to eat/drink at the restaurant. Return all such combinations of dishes from the menu, which I can pay for in given amount.

Explanation:

Menu:
Noodle  $12.87
Rice    $8.23
Soup    $5.76
Coke    $3.12
Pizza   $10.89

Amount:  $30

Output: 
{{Noodle,Rice,Soup,Coke}, 
{Noodle,Pizza,Soup}, 
{Pizza,Rice,Soup,Coke}, 
{Noodle,Noodle,Coke}, 
{Noodle,Rice,Rice}, 
{Rice,Rice,Rice,Coke}, 
{Soup,Soup,Soup,Pizza},
{Coke,Coke...9x},
{Pizza,Pizza,Coke,Coke}}

As,  
Noodle+Rice+Soup+Coke = 29.98
Noodle+Pizza+Soup = 29.52
Pizza+Rice+Soup+Coke = 28 ...so on

Note: The amount we aggregate should be closest to the given amount i.e in this case $30

Comments