Easy C++ Solution using binary search
\n\n# Code\n\n//TC=O(nlogn)\nclass Solution {\npublic:\nint search(vector<int>& nums,int t,int s){\n    int e=nums.size()-1;\n    while(s<=e){\n        int mid=
\n\n# Code\n```\n//TC=O(nlogn)\nclass Solution {\npublic:\nint search(vector<int>& nums,int t,int s){\n    int e=nums.size()-1;\n    while(s<=e){\n        int mid=s+(e-s)/2;\n        if(nums[mid]==t)\n        return mid;\n        else if(t>nums[mid])\n        s=mid+1;\n        else\n        e=mid-1;\n    }\n    return -1;\n}\n    int findPairs(vector<int>& nums, int k) {\n        sort(nums.begin(),nums.end());\n        set<pair<int,int>> ans;\n        int i=0;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(search(nums,nums[i]+k,i+1)!=-1)\n            ans.insert({nums[i],nums[i]+k});\n        }\n        return ans.size();\n    }\n};\n```
['C++']