Count Pair With given Sum using map
Vishal Yadav
Posted on January 22, 2022
Solution
#include<bits/stdc++.h>
using namespace std;
void fun(int arr[],int n,int k)
{
}
int main()
{
int arr[]={1,2,5,4,0};
int n=5;
int k=5;
unordered_map<int,int>m;
int c=0;
for(int i=0;i<n;i++)
{
c+=m[k-arr[i]];
m[arr[i]]++;
}
cout<<c;
return 0;
}
💖 💪 🙅 🚩
Vishal Yadav
Posted on January 22, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.