You are viewing a single comment's thread. Return to all comments →
My answer is pretty simple. I've put all values on a map in C++ and just added the values n*(n-1).
Solution:
#include <bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ int a, b, ans=0; cin >> a; int arr[a]; map<int, int> mp; for(int i=0; i<a; i++){ cin >> b; mp[b] += 1; } for(map<int, int>::iterator itr = mp.begin(); itr != mp.end(); itr++) ans += itr->second * (itr->second-1); cout << ans << endl; } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Pairs
You are viewing a single comment's thread. Return to all comments →
My answer is pretty simple. I've put all values on a map in C++ and just added the values n*(n-1).
Solution: