Trains the technique from
LeetCode 983Minimum Cost For TicketsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
You already know which days of the year you will ride the harbour ferry. trips
lists those day numbers in strictly increasing order, counting day 1 as the first
day of the year.
The ferry sells three kinds of pass and prices gives their costs in this order:
prices[0] buys a pass valid for 1 day.prices[1] buys a pass valid for 7 days in a row.prices[2] buys a pass valid for 30 days in a row.A pass starts on any day you name and stays valid for its whole span of
consecutive days, whether or not you ride on each of them. You may buy as many
passes as you like, and every day listed in trips has to fall inside the span
of at least one pass.
Return the smallest total you can spend.
Example 1
A 1-day pass on day 3 covers the only ride and costs 5.
Example 2
One 7-day pass starting on day 5 stays valid through day 11, so it covers all seven rides, for 10.
Example 3
One 30-day pass starting on day 12 stays valid through day 41, which covers every ride, for 27.
Example 4
Four 7-day passes starting on days 15, 29, 44 and 52 cover the rides, and the last of them covers days 52, 54 and 55 together. Four passes at 6 each is 24.
Example 5
Four 1-day passes, one on each riding day, cost 12 in total.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def mincost_tickets(trips: list[int], prices: list[int]) -> int:public int mincostTickets(int[] trips, int[] prices)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.