Problem · Array
EasyRoblox logoRobloxOA
See Roblox hiring insights

Problem statement

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.

Function

countPairs(a: int[]) → int

Examples

Example 1

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

Constraints

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

More Roblox problems

drafts saved locally
public int countPairs(int[] a) {
    // write your code here
}
a[3, 5, 1, 7, 8, 10, 62, 13]
expected5
checking account