FastPrepFastPrep
Problem Brief

Count Pairs

OA

Given an array of positive integers a, your task is to count the number of pairs i and j (where 0<= i < j < a.length), such that a[i] and a[j] have the same number of 1s in their binary representations.

1Example 1

Input
a = [3, 5, 1, 7, 8, 10, 62, 13]
Output
5
Explanation
Example 1 illustration
see image

Constraints

Limits and guarantees your solution can rely on.

N/A (If you know about it, feel free to contact us. TYVM!)

public int countPairs(int[] a) {
    // write your code here
}
Input

a

[3, 5, 1, 7, 8, 10, 62, 13]

Output

5

Sign in to submit your solution.