1332. Count of Pairs with AND Equal to Zero

MediumBit ManipulationBit ManipulationPairsCounting

Given an array of non-negative integers, count the index pairs (i, j) with i < j whose bitwise AND is zero, meaning the two values share no set bit.

Input: A JSON object {"nums": [<non-negative integers>]}.

Output: Return the number of pairs whose AND equals 0.

Examples

Example 1
Input: {"nums":[1,2,4]}
Output: 3
Explanation: Every pair uses distinct bits -> 3.
Example 2
Input: {"nums":[3,3]}
Output: 0
Explanation: 3 AND 3 = 3, not zero -> 0.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →