Editor

Peak Users Online

#370 · Working with data · Advanced · 130 XP · about 25 min

A chat server logs every session as (user, login, logout), with times as strings 'HH:MM:SS' (two digits each) on a single day. A session is online from its login time up to, but not including, its logout time: someone who logs out at 10:00:00 is already gone when someone else logs in at 10:00:00. Logout is always later than login, and a user never has two sessions online at once.

Write peak_online(sessions) that returns a tuple (peak, start, end): the largest number of sessions online at the same moment, the first time that number is reached, and the first time after that when fewer are online. start and end are 'HH:MM:SS' strings.

Examples

sessions = [
    ('ana', '09:00:00', '11:00:00'),
    ('ben', '09:30:00', '10:00:00'),
    ('cy', '10:00:00', '10:45:00'),
    ('dee', '10:15:00', '12:00:00'),
]
peak_online(sessions)  # returns (3, '10:15:00', '10:45:00')

peak_online([('a', '08:00:00', '09:00:00'), ('b', '09:00:00', '10:00:00')])
# returns (1, '08:00:00', '10:00:00')

In the first example, at 10:00:00 Ben leaves as Cy arrives, so two people stay online. From 10:15:00 Ana, Cy and Dee are all online, until Cy leaves at 10:45:00. In the second, someone is online without a break from 08:00:00 to 10:00:00.

Constraints

  • 1 <= len(sessions) <= 100000

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.