There is this problem : Link
Sample Input:
5 2
1 5 3 4 2
Sample Output:
3
Solution 1:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
int main()
{
ll n,k,a,count=0; cin>>n>>k;
map <ll,ll> record;
for(ll i=0;i<n;i++)
{
cin>>a;
record[a]++;
}
for(auto a:record)
{
ll diff=a.fi-k;
if(record[diff]!=0)
count++;
}
cout<<count;
}
Solution 2:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
int main()
{
ll n,k,a,count=0; cin>>n>>k;
unordered_map <ll,ll> record;
for(ll i=0;i<n;i++)
{
cin>>a;
record[a]++;
}
for(auto a:record)
{
ll diff=a.fi-k;
if(record[diff]!=0)
count++;
}
cout<<count;
}
Problem: Both the solutions are moreover the same the only difference is i have used unordered map in one and map in other but there is difference in the output of the both Solution one gives the output 1 whereas solution 2 gives the output 0.
(I am using Sublime text as editor with C++17)
Why? Can anybody explain?
Thanks in advance !