Skip to the code
cf.
+25 XP

#57 Peak Concurrent Viewers

medium

A video platform logs each viewing session as [start, end] in whole minutes of the day: the viewer is watching during minutes start to end - 1 (the end minute is not included).

Write peakViewers(sessions) that returns [peak, minute]: the largest number of viewers watching during the same minute, and the earliest minute when that happens. If there are no sessions, return [0, 0].

Example 1

Input: sessions = [[0,30],[10,40],[20,25],[35,60]]
Output: [3,20]

From minute 20 to 24, three sessions overlap. That first happens at minute 20.

Example 2

Input: sessions = [[5,10],[10,15]]
Output: [1,5]

The first session ends just as the second starts, so they never overlap.

Constraints

  • 0 <= sessions.length <= 10^5
  • 0 <= start < end <= 1440
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

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