Skip to main content
LeetCode 982, Hard. Topics: Array, Hash Table, Bit Manipulation. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 22 parametrized pytest cases, and a playground notebook:

Problem

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.

Examples

Constraints

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

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026