values and an integer quorum. Hold a vote on each bit: every number "votes" for the positions where its binary form has a one.
A bit makes it into the answer if at least quorum numbers voted for it. Return the number whose binary form has ones in exactly those positions.
With quorum = 1 this is the plain bitwise OR of all the numbers, and with quorum = len(values) it is the bitwise AND.values=[5, 6, 3, 4], quorum=2 → 7
In binary these are 101, 110, 011 and 100. Bit 0 is set in 5 and 3 (two votes), bit 1 in 6 and 3 (two), bit 2 in 5, 6 and 4 (three). Every bit reaches the quorum: 111 = 7.
values=[5, 6, 3, 4], quorum=3 → 4
Only bit 2 gets three votes, so the answer is 100 = 4.
values=[9, 1, 0], quorum=3 → 0
values=[5, 6, 3, 4], quorum=2
7
Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.