Peak Hour from Reservations

Hard ⏱ 18 min 30% acceptance ★★★★★ 4.8
Reservations are (start_hour, end_hour) integer tuples (end exclusive) for one evening. Write peak_hour(reservations) returning the hour with the most simultaneous tables occupied — the smallest such hour on ties. Sweep hour by hour over 0-23 counting overlaps.

Examples

Example 1
Input
peak_hour([(18, 20), (19, 21), (19, 22)])
Output
19
Explanation

All three parties overlap during hour 19.

Constraints

  • End hour is exclusive.
  • Ties → earliest hour.
  • Empty input → None.

Topics

Business Logicinterval counting

Companies

ZomatoDineoutOpenTable

Hints

Hint 1

For each hour h, count start <= h < end.

Hint 2

max over hours with the count as key handles ties if you iterate ascending.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.