Ctrl K

Picks With the Full OR

Medium
You get an array of positive integers values. You may pick any non-empty set of its elements and take the bitwise OR of the picked numbers. Find the largest OR any pick can reach and return how many picks reach it. Picks are told apart by the positions of the chosen elements: if two equal numbers sit at different positions, taking one or the other gives two different picks.
Example 1
values=[4, 2, 6] → 5

The largest possible OR is 6. It comes from [6], [4, 2], [4, 6], [2, 6] and [4, 2, 6], five picks in total.

Example 2
values=[9, 9] → 3

Every non-empty pick gives 9: the first 9, the second 9, and both. Equal values at different positions count as different picks.

Example 3
values=[1, 2, 4, 8] → 1
Constraints
  • 1 ≤ len(values) ≤ 16
  • 1 ≤ values[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsOutshoot the Rival MediumColumns That Cover Rows MediumStrongest Product Team MediumMoves Between Offices HardXOR of Every Subset Easy
loading Python…
Input
values=[4, 2, 6]
Expected
5

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