Your app calls a paid map API only on some days of the year, listed in days in increasing order (days are numbered 1 to 365). The provider sells three passes: 1 day for prices[0], 7 consecutive days for prices[1], and 30 consecutive days for prices[2]. A pass bought on day d covers days d to d + 6 (or d + 29).
Write cheapestPlan(days, prices) that returns the least total cost to cover every day in days.
Input: days = [2,5,7,8,9,21], prices = [2,7,15] Output: 11
A 1-day pass on day 2 (2), a 7-day pass covering days 5 to 11 (7), and a 1-day pass on day 21 (2).
Input: days = [2,3,4,5,6,7,8,9,10,11,31,32], prices = [2,7,15] Output: 17
A 30-day pass for days 2 to 31 (15) and a 1-day pass on day 32 (2).
1 <= days.length <= 3651 <= days[i] <= 365, strictly increasingprices.length === 3, 1 <= prices[i] <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #500 Cheapest API Plan for Busy Days. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.