Triples with Bitwise AND Equal To Zero

Given an integer array nums, return the number of AND triples.

An AND triple is a triple of indices (i, j, k) such that:

  • 0 <= i < nums.length
  • 0 <= j < nums.length
  • 0 <= k < nums.length
  • nums[i] & nums[j] & nums[k] == 0, where & represents the bitwise-AND operator.
Example 1
Inputnums = [2,1,3]
Output12
There are 12 index triples (i, j, k) whose bitwise AND value is 0.
Example 2
Inputnums = [0,0,0]
Output27
All 27 possible triples have bitwise AND equal to 0 because every value is 0.

Constraints

  • 1 <= nums.length <= 1000
  • 0 <= nums[i] < 2^16

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate