Find the number of duplicates index pairs (p,q) in an array such that p<q.
You can write the program in Java. P and Q refers to the index.

Input: 1 3 -4 1 -2 3 1 6 8 1 -4 2 1 60 90

What I have tried:

Java

import java.util.*;
class GFG {
// Return the number of pairs with equal// values.staticint countPairs(int arr[], int n)
{
int ans = 0;
// for each index i and jfor (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++)
// finding the index with same// value but different index.if (arr[i] == arr[j])
ans++;
return ans;
}
//driver codepublicstaticvoid main (String[] args)
{
int arr[] = { 1, 3, -4, 1, -2, 3, 1, 6, 8, 1, -4, 2, 1, 60, 90};
int n = arr.length;
System.out.println(countPairs(arr, n));
}
}

I tried this but it doent work as The Question is asking me??

What have you tried to fix it?

Where are you stuck?

What help do you need?