Minimum Cost to Attend Required Courses
Learn this problemProblem statement
You must attend courses on the days listed in courseDays, which is sorted in strictly increasing order. You may buy any of the reusable pass options described by the parallel arrays passDurations and passCosts.
If you buy option j on day d, it costs passCosts[j] and covers every required course day from d through d + passDurations[j] - 1, inclusive. You may buy an option on the first required course day that is not already covered.
Return the minimum total cost needed to cover every required course day. If courseDays is empty, return 0.
Function
minimumCourseCost(courseDays: int[], passDurations: int[], passCosts: int[]) → intExamples
Example 1
courseDays = [1,4,6,7,8,20]passDurations = [1,7,30]passCosts = [2,7,15]return = 11Buy one-day passes for days 1 and 20, and a seven-day pass on day 4 to cover days 4, 6, 7, and 8. The total cost is 2 + 7 + 2 = 11.
Example 2
courseDays = [1,2,3,4,5,6,7,8]passDurations = [1,3,8]passCosts = [3,6,14]return = 14An eight-day pass bought on day 1 covers every required day for cost 14, which is cheaper than combining shorter passes.
Example 3
courseDays = []passDurations = [1,7]passCosts = [4,18]return = 0No course days require coverage, so no pass is purchased.
Constraints
0 <= courseDays.length <= 100000courseDayscontains distinct positive integers in strictly increasing order.1 <= passDurations.length = passCosts.length <= 1001 <= passDurations[i] <= 10000000001 <= passCosts[i] <= 1000000- The minimum total cost fits in a signed 32-bit integer.
More Visa problems
- Minimum Score of a Path Between CitiesOA · Seen Jul 2026
- Planning ProductionOA · Seen Jul 2026
- Subarray SumOA · Seen Jul 2026
- Maximum Even Tag SumOA · Seen Jun 2026
- Transform Binary MatrixOA · Seen Jun 2026
- Minimum Cost to Select People for Skill QuotasOA · Seen May 2026
- Longest Selectable Non-Decreasing SubarrayOA · Seen Apr 2026
- Maximize Capped Contribution SumOA · Seen Apr 2026