Ad-free passes
Write code · Medium · §10.2 Filling a one-dimensional table
On a video social network, you need a pass to watch without ads. A one-day pass costs price1 won and can be used only on the day it is bought. A one-week pass costs price7 won and can be used for 7 days starting on the day it is bought. For example, a one-week pass bought on day 3 lets you watch without ads from day 3 to day 9.
days holds the numbers of the days on which you will watch videos this year, from smallest to largest. You buy passes so that you watch without ads on every one of those days. Complete the function solution, which returns the smallest amount of money you have to spend. You may buy a pass on any day.
Function
solution(days, price1, price7)
Constraints
- The length of
daysis from 1 to 365. - The elements of
daysare different integers from 1 to 365, in increasing order. price1andprice7are integers from 1 to 10,000.
Examples
| days | price1 | price7 | result |
|---|---|---|---|
[2, 3, 4, 9, 10, 11, 12, 25] | 3 | 10 | 22 |
[3, 4, 5, 6] | 4 | 10 | 10 |
Starter code
def solution(days, price1, price7):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.