Ctrl K

Triples With a Zero AND

Hard
You are given an array of non-negative integers values. Count the ordered triples of indices (i, j, k) such that values[i] & values[j] & values[k] == 0, where & is bitwise AND. Indices may repeat, and triples that differ only in the order of their indices count separately.
Example 1
values=[1, 6] → 6

1 & 6 = 0, so any triple that uses both indices works: of the 8 triples only (0, 0, 0) and (1, 1, 1) fail, so the answer is 6.

Example 2
values=[7, 7] → 0

Every triple gives 7 & 7 & 7 = 7.

Example 3
values=[0] → 1

The only triple, (0, 0, 0), gives 0.

Constraints
  • 1 ≤ len(values) ≤ 1000
  • 0 ≤ values[i] < 2¹⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSquare-Sum Chains HardWords That Fit Each Puzzle HardTurn Every Lamp Off HardBest XOR Up the Chain of Command HardSwapped Initials Names Hard
loading Python…
Input
values=[1, 6]
Expected
6

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