Peak hour per zone: hints, no solution
Medium · Arrays & hashing
A warehouse is divided into numbered zones. Every time a picker takes an item, the system logs a pick event: event i happened in zone zones[i] during hour of the day hours[i], where the hour is a whole number from 0 to 23.
For each zone that has at least one pick, work out its busiest hour, meaning the hour with the most pick events in that zone. If several hours share the top count, choose the earlier hour. Return one pair per zone holding the zone and its busiest hour, sorted by zone ascending. Return an empty list if there are no events.
Examples
- Input
- zones = [2, 1, 2, 2, 1], hours = [9, 14, 9, 10, 14]
- Output
- [[1, 14], [2, 9]]
- Note
- Zone 1 peaks at hour 14 and zone 2 peaks at hour 9.
- Input
- zones = [3, 3, 3, 3], hours = [15, 8, 15, 8]
- Output
- [[3, 8]]
- Note
- Hours 8 and 15 tie with two picks each, so the earlier hour 8 wins.
- Input
- zones = [4], hours = [23]
- Output
- [[4, 23]]
- Note
- A single event makes its own hour the peak.
Constraints
- zones.length == hours.length, 0 <= length <= 195000
- 1 <= zones[i] <= 1000000
- 0 <= hours[i] <= 23
Hint 1: a nudge
What would you like to have counted for a zone before you can name its busiest hour?
Unlock the full hints and timed practice with a pass
The second and third hints and the timed, runner-checked practice are part of a pass.