forked from deepanshumishra/JavaAndCPP_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEQPAIR.java
More file actions
39 lines (32 loc) · 757 Bytes
/
Copy pathEQPAIR.java
File metadata and controls
39 lines (32 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package codechef_lib;
import java.util.HashMap;
import java.util.Scanner;
public class EQPAIR {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int cases=sc.nextInt();
while(cases--!=0) {
//For every Testcase
int n=sc.nextInt();
long ans=0;
//Arr
int arr[] = new int[n];
HashMap<Integer,Long> map = new HashMap<>();
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
long val=map.getOrDefault(arr[i], (long)0);
val++;
map.put(arr[i], val);
}
for(Integer e:map.keySet()) {
long cnt=map.get(e);
if(cnt>1) {
ans+=(long)cnt*(cnt-1)/2;
}
}
System.out.println(ans);
}
}
}
//AC