We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<cmath>#include<limits>#include<set>#include<iostream>#include<algorithm>#include<iterator>usingnamespacestd;#define ll long long intintmain(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);lln,ans=numeric_limits<ll>::max();cin>>n;multiset<ll>mySet;for(autoi=0;i<n;++i){lltemp=0;cin>>temp;mySet.insert(temp);}for(autoitr=mySet.begin();itr!=mySet.end();++itr)if(itr!=mySet.begin()){lla=*(itr--);llb=*(itr++);ans=min(ans,abs(a-b));}cout<<ans<<endl;return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Absolute Difference in an Array
You are viewing a single comment's thread. Return to all comments →
without sorting: using multiset;