✅Multiple solutions in C++ with explanations!
\n> If you\u2019re interested in coding you can join my Discord Server, link in the comment section. Also if you find any mistake please let me know. Thank you!
\n> **If you\u2019re interested in coding you can join my Discord Server, link in the comment section. Also if you find any mistake please let me know. Thank you!\u2764\uFE0F**\n> \n\n---\n\n## Explanation:\n\n### Solution 01\n\n- Here we sort the vector to avoid duplicate elements in the set.\n- Take to loops & if the difference is equal to k, push it to set.\n- Calculate the set size in the count variable and return it.\n- **Time complexity:** O(n^2 logn).\n\n### Solution 02\n\n- Here we sort the values and store the element occurrence in the map.\n- If k=0, then the difference of 2 same elements will be equal to 0.\n- If not then we\u2019ll iterate the map & will find if the ***(k-current element)*** is present in the map.\nIf present then we\u2019ll increase count.\n- Also every time we\u2019ll remove the current element from map to avoid repeating elements.\n- **Time complexity:** O(nlogn).\n\n---\n\n## Code:\n\n```cpp\n//Solution 01:\n**class Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        int n= nums.size();\n        int count=0;\n        sort(nums.begin(), nums.end());\n        set<vector<int>>res;\n        \n        for(int i=0; i<n-1; i++){\n            for(int j=i+1; j<n; j++){\n                if(abs(nums[i]-nums[j])==k)\n                    res.insert({nums[i], nums[j]});\n            }\n        }\n        count = res.size();\n        return count;\n    }\n};**\n\n//Solution 02:\n**class Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        int n= nums.size();\n        int count=0, l=0, r=n-1;\n        sort(nums.begin(), nums.end());\n        unordered_map<int, int>mp;\n        \n        if(k<0) return 0;\n        \n        for(auto x: nums)\n            mp[x]++;\n\n        if(k==0){\n            for(auto x:mp){\n                if(x.second>1)\n                    count++;\n            }\n        }\n        else{\n            for(auto x:mp){\n                x.second--;\n                if(mp.count(x.first-k))\n                    count++;\n                x.second++;\n            }    \n        }\n        \n        return count;\n    }\n};**\n```\n\n---\n\n> **Please upvote this solution**\n>
['C', 'Ordered Set', 'C++']