Skip to contentKEEP THE CRAFTTHE SANCTUARY

Find Peak Active Sessions

Turn sessions into start and end events, sort them, and track the largest running count.

The problem

Implement peak_active_sessions(sessions). Each session is a half-open time range [start, end) with start < end: it is active from start up to, but not including, end. Return the largest number of sessions that are active at the same moment, which is also the smallest number of rooms needed to host them all. A session that ends at time t and one that starts at time t are never active together. There are 0 to 100,000 sessions, and 0 <= start < end <= 1,000,000.

Starter code

def peak_active_sessions(sessions):
    pass

Public examples

  1. sessions = [[1, 5], [2, 6], [4, 7]]gives3
  2. sessions = [[1, 3], [3, 5], [5, 8]]gives1
  3. sessions = [[1, 10], [2, 3], [4, 5]]gives2

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.