 # can't figure out missing corner cases

I have this question from a past contest that i participated in. I just can’t figure out what corner cases am I missing out on as two of the test cases ain’t giving correct answers. Plz help.
My Code: https://www.hackerrank.com/contests/freshers-challenge-3/challenges/fcp/submissions/code/4355231
Thanks

Plzz help someone!

Method 1: Using sorting

``````for _ in range(input()):
n = input();i=1;temp=1;ans=0
a=map(int,raw_input().split())
a.sort()
while(i<n):
if(a[i]==a[i-1]):
temp+=1
i+=1
else:
ans+=temp*(temp-1)
i+=1
temp=1
ans+=temp*(temp-1)
print ans
``````

Method 2: Counting frequency
for _ in range(input()):
a=1000005
n=input()
ans=0
b=map(int,raw_input().split())
for i in range(n):
a[b[i]]+=1
for i in range(1000005):
ans+=a[i]
(a[i]-1)
print ans

I used above two methods and got accepted in all test cases for both. I could not access your code but hope above two python codes will help you.

1 Like

Thanks.

Can you review my code once?

``````
int t,n,i,j,m,c,s;
vector<int>vec;
int main() {
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=0;i<n;++i){
scanf("%d",&m);
vec.push_back(m);
}
sort(vec.begin(),vec.end());
s=0;
for(i=0;i<n;++i){
m=vec[i];
c=1;

for(j=i+1;(vec[j]<=m)&&(j<n);j++){
c++;
}
s+=c*(c-1);
i+=c-1;

}
printf("%d\n",s);
vec.clear();
}
return 0;
}</pre>
``````
//