Skip to the code
+50 XP

#580 Most Clips Across k Players

hard

A video wall has k players. Each scheduled clip is [start, end] in seconds and must play on one player from its start to its end. A player shows one clip at a time; a clip may start on a player at the exact second its previous clip ends.

Write mostClips(clips, k) that returns the largest number of clips that can be fully played. There can be up to 100,000 clips and 100,000 players, so checking every player for every clip is too slow.

Example 1

Input: clips = [[0,4],[1,3],[2,6],[4,7],[5,8]], k = 2
Output: 4

One player shows [1, 3] then [4, 7]; the other shows [0, 4] then [5, 8]. Any three of the first three clips overlap at time 2, so one of them must be dropped.

Example 2

Input: clips = [[0,10],[0,10],[0,10]], k = 2
Output: 2

Only two players, and all clips overlap.

Constraints

  • 0 <= clips.length <= 100000
  • 1 <= k <= 100000
  • 0 <= start < end <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).