Ctrl K

Bits With Enough Votes

Easy
You get an array of non-negative integers 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.
Example 1
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.

Example 2
values=[5, 6, 3, 4], quorum=3 → 4

Only bit 2 gets three votes, so the answer is 100 = 4.

Example 3
values=[9, 1, 0], quorum=3 → 0
Constraints
  • 1 ≤ len(values) ≤ 50
  • 0 ≤ values[i] < 2³¹
  • 1 ≤ quorum ≤ len(values)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Unpaired Value EasyThe Lost Ticket EasyDoubled Tag, Lost Tag EasyMirror and Negate a Bitmap EasyMultiple of Five at Every Step Easy
loading Python…
Input
values=[5, 6, 3, 4], quorum=2
Expected
7

Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.