You're planning a year-long travel adventure! ๐ You have a list of specific days when you'll be traveling, and you need to buy train tickets in the most cost-effective way possible.
The Challenge: Train tickets come in three types:
1-day pass- costscosts[0]dollars, valid for 1 day7-day pass- costscosts[1]dollars, valid for 7 consecutive days30-day pass- costscosts[2]dollars, valid for 30 consecutive days
Important: When you buy a multi-day pass, it covers consecutive calendar days starting from the purchase date, regardless of whether you actually travel on those days.
For example, if you buy a 7-day pass on day 2, it covers days 2, 3, 4, 5, 6, 7, and 8.
Goal: Find the minimum cost to cover all your planned travel days given in the array days.
Input & Output
Visualization
Time & Space Complexity
Each day index is calculated exactly once and stored in memo table
Memoization table stores results for up to n day indices, plus recursion stack
Constraints
- 1 โค days.length โค 365
- 1 โค days[i] โค 365
- days is in strictly increasing order
- costs.length == 3
- 1 โค costs[i] โค 1000