Watching shows without overlap
Write code · Challenge · §6.3 Greedy
shows holds the schedules of live shows. [s, e] is a show that starts at minute s and ends at minute e. You can watch only one show at a time, and you watch each show you choose from start to finish. A show that starts at the moment another show ends can be watched right after it.
Complete the function solution, which returns the largest number of shows you can watch.
Function
solution(shows)
Constraints
- The length of
showsis from 1 to 100,000. sandeare integers from 0 to 1,000,000,000, andsis less thane.- Several shows may have the same start and end times.
Examples
| shows | result |
|---|---|
[[1, 3], [2, 5], [4, 6]] | 2 |
[[60, 90], [0, 50], [55, 70], [80, 100]] | 3 |
Starter code
def solution(shows):
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.