Most Open Doors
Easy · bit manipulation
A museum has several floors, numbered from 0. Each floor has up to 31 doors, also numbered from 0. Every evening a sensor on each floor reports one whole number: door j is open when the binary digit at position j of that number (counting from the right, starting at 0) is 1, and closed when it is 0.
For example, the reading 13 is 1101 in binary, so doors 0, 2 and 3 are open and door 1 is closed.
You are given the list readings, where readings[i] is the reading of floor i. Return the number of the floor that has the most open doors. If several floors tie, return the lowest floor number.
Examples
Example 1
Input: readings = [1, 7, 6]
Output: 1
Floor 0 has one open door, floor 1 has three (7 is 111) and floor 2 has two (6 is 110).
Example 2
Input: readings = [5, 3, 8]
Output: 0
Floors 0 and 1 both have two open doors and floor 2 has one. The tie goes to the lower number, 0.
Example 3
Input: readings = [0]
Output: 0
There is only one floor, so it is the answer even though all its doors are closed.
Constraints
- 1 <= len(readings) <= 10^5
- 0 <= readings[i] <= 2^31 - 1