Busiest request hour

arrays

Busiest request hour

Lyft Python Interview Question

Lyft's marketplace team wants to know which hour of the day gets the most ride requests in a city, so it can plan driver bonuses.

Write a function busiest_hour(request_hours) that takes a list with the hour of each ride request, from 0 to 23, and returns the hour with the most requests. If several hours tie, return the earliest of them. The list always has at least one request.

Asked of

  • Data Engineer
  • Data Scientist
  • Analytics Engineer
  • ML Engineer
  • AI Engineer

Example 1

Input

busiest_hour([8, 9, 8, 17, 8, 17])

Output

8

Example 2

Input

busiest_hour([23, 0, 0, 23])

Output

0

Explanation

In the first example, hour 8 appears three times and hour 17 twice, so the answer is 8. In the second example, hours 0 and 23 both appear twice, so the earlier hour, 0, is returned.

Submit also runs 3 hidden test cases that check edge cases.