P15 · 1 second · 256 MB

Movie Festival

You are given `intervals` as `[start, end]` pairs. You may watch a film if its start is **greater than or equal to** the previous film's end (touching is allowed). Return the maximum number of films you can watch. `intervals` may be empty.

function movieFestival(intervals) → number

CONSTRAINTS

  • 0 ≤ intervals.length ≤ 2000
  • 0 ≤ start < end ≤ 10⁹
Input: intervals = [[1, 4], [2, 3], [4, 6], [3, 5]]
Output: 2
Take [2,3] then [4,6], or [2,3] then [3,5].
Input: intervals = [[1, 100], [2, 3], [4, 5]]
Output: 2
The long film blocks both shorts if you take it first.
1
2
3
4
5
6
7
8

Arena judges JavaScript in a Web Worker (1s wall-clock, then TLE). Samples are public; submit runs hidden tests too. C++/Python is a later swarm package.