Minimum Cost for Tickets
Updated
Problem statement
You travel on every day listed in the strictly increasing array days. A travel pass is valid for 1, 7, or 30 consecutive calendar days, including its purchase day. Their costs are costs[0], costs[1], and costs[2].
Return the minimum total cost needed to cover every travel day.
Function
minTicketCost(days: int[], costs: int[]) → intExamples
Example 1
days = [1,4,6,7,8,20]costs = [2,7,15]return = 11Buy a 1-day pass on day 1, a 7-day pass on day 4, and a 1-day pass on day 20.
Example 2
days = [1,2,3,4,5,6,7,8,9,10,30,31]costs = [2,7,15]return = 17A 30-day pass starting on day 1 covers days 1 through 30, and a 1-day pass covers day 31.
Constraints
1 ≤ days.length ≤ 3651 ≤ days[i] ≤ 365daysis strictly increasing.costs.length == 31 ≤ costs[i] ≤ 1000
More Roku Onsite Interview questions
Similar questions at other companies
- Longest Increasing SubsequenceAmazon · ONSITE INTERVIEW
- Minimum Removals for a Nice ArrayAdobe · ONSITE INTERVIEWAdobe interview questions
- Longest Increasing SubsequenceMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Longest Increasing SubsequenceExpedia · ONSITE INTERVIEWExpedia interview questions
- Longest Increasing SubsequencePeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Maximum Total Length of Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions