Practice · 2 of 4
Count equal pairs
CHALLENGE
Difficulty: beginner+25 XP
Implement countPairs(int[] a): count index pairs i < j where a[i] == a[j]. The double loop over i then j (starting at i + 1) is the honest O(n squared) approach — fine here.
Press Submit to check your solution.
Back to lesson: Practice: Algorithmic reasoning reps