Count the number of index pairs whose values are equal.
You are given an integer array nums. A pair of indices (i, j) is called a good pair if:
0 <= i < j < nums.lengthnums[i] == nums[j]Return the total number of good pairs in the array.
The task is to count all valid index pairs, not just distinct values.
nums.In an interview setting, the array is provided directly as input; on platforms it is typically given in the problem's standard format.
(i, j) such that i < j and nums[i] == nums[j].1 <= nums.lengthExample 1
Input
nums = [1,2,3,1,1,3]
Output
4
Explanation
The good pairs are (0,3), (0,4), (3,4), and (2,5).
Example 2
Input
nums = [1,1,1,1]
Output
6
Explanation
Every pair of indices is good. There are 4 choose 2 = 6 such pairs.
Example 3
Input
nums = [1,2,3]
Output
0
Explanation
No two different indices contain the same value.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.