Maximum Restaurants Reachable Within Budget

Problem Given a list of restaurants — each with a distance from the origin, a meal cost, and a rating — plus a maxBudget and a minRating, find the maximum number of restaurants you can visit in a single outing. Each restaurant is visited at most once, travel starts at the origin, and travel cost between two points equals the absolute difference of their distances from the origin.

Input / Output

  • Input: an array of {distance, cost, rating}, plus maxBudget and minRating.
  • Output: the largest number of restaurants visitable without exceeding the budget.

Constraints

  • n ≤ 1000.
  • Total spend = sum of chosen meal costs + total travel cost, and must not exceed maxBudget.
  • Only restaurants with rating ≥ minRating qualify.

Example

  • restaurants=[{d:1,c:20,r:4.5},{d:3,c:30,r:4.0},{d:5,c:10,r:3.5}], maxBudget=60, minRating=4.0 → 2. The d:5 restaurant is filtered by rating; visiting d:1 then d:3 costs meals 20+30=50 plus travel 3 = 53 ≤ 60.
  • Tricky case: a cheap meal far away can be worse than two pricier meals nearby, because the farthest restaurant sets the entire travel bill.
asked …
LeaderboardSalaryAccount