#C10157. Counting Good Pairs
Counting Good Pairs
Counting Good Pairs
You are given an integer array nums
of size n. A pair of indices (i, j)
is called a good pair if and only if:
\( nums[i] = nums[j] \) and \( i < j \).
Your task is to count the total number of good pairs present in the array.
Note: The formula to calculate the number of pairs for a group of identical numbers with frequency \( f \) is given by:
\( \frac{f \times (f-1)}{2} \).
inputFormat
The first line contains an integer n
denoting the number of elements in the array.
The second line contains n
space-separated integers representing the elements of the array nums
.
outputFormat
Output a single integer, which is the count of good pairs in the array.
## sample6
1 2 3 1 1 3
4
</p>