1395. Count Pairs with AND Greater Than XOR

HardBit ManipulationBit MathCountingHighest Bit

Given an array of positive integers, count the pairs of indices (i, j) with i < j for which nums[i] AND nums[j] is strictly greater than nums[i] XOR nums[j].

Input: A JSON object {"nums": [<positive integers>]}.

Output: Return the number of pairs whose AND exceeds their XOR.

Examples

Example 1
Input: {"nums":[1,2,3,4,5,6,7]}
Output: 7
Explanation: Groups of size 1, 2 and 4 give 7 qualifying pairs.
Example 2
Input: {"nums":[1,2,4,8]}
Output: 0
Explanation: No two share a highest bit -> 0.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →