Uber phone screen - Combinations of dishes from the menu

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 (6)