Ctrl K

Pairs of Equal Values

Easy
You are given an integer array values. Count the index pairs (i, j) with i < j and values[i] == values[j].
Example 1
values=[4, 9, 4, 4, 9] → 4

The three 4s give three pairs and the two 9s give one more, 4 in total.

Example 2
values=[2, 5, 8] → 0

All values differ, so there are no pairs.

Example 3
values=[6] → 0
Constraints
  • 1 ≤ len(values) ≤ 10⁵
  • 1 ≤ values[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEven Piles of Cards EasyCoprime Digit Pairs EasyPairs Balanced by Their Mirrors MediumPhoto Frames of the Same Shape MediumPairs Off the Pace Medium
loading Python…
Input
values=[4, 9, 4, 4, 9]
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 105 tests on the server, hidden ones included.