vector<pair<int,int>>pairDifference(vector<int>arr){// store all the numbers in a set for ease of searching// cpp set stores all numbers in ascending order by defaultset<int>numbers(arr.begin(),arr.end());// stores the pairs which have difference of twovector<pair<int,int>>numPairs;for(intnum:numbers){// for any number num if num+2 is also in the set// then include it in the vectorif(numbers.find(num+2)!=numbers.end()){numPairs.push_back(make_pair(num,num+2));}}returnnumPairs;}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
C++ solution