#include <bits/stdc++.h> int pairSum(vector<int> &arr, int n, int target) { int count=0; unordered_map<int,int>mp; for(int i=0 ; i<n ; i++) { if(mp.find(target-arr[i])!=mp.end()) { count+=mp[target-arr[i]]; } else { mp[arr[i]]++; } } if(count==0) return -1; else return count; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter