[C++] Solution w/ Explanation| Brute force to optimize | Two approaches
Brief note about Question-\n\nWe have to  return the number of unique k-diff pairs in the array.\n\nK- diff pair (arr[i], arr[j]) is nothing but basically \n 0 
***Brief note about Question-***\n\nWe have to  ***return the number of unique k-diff pairs in the array.***\n\nK- diff pair (arr[i], arr[j]) is nothing but basically \n* 0 < i < j < arr.size()\n* abs(arr[i] - arr[j]) == k\n______________\n***Solution - I (Accepted)-***\n* We try to implement what the question wants to do, like this is the most basic thing we can do.\n* We traverse from all of the array and find unique pairs where their absoloute difference is k and increment our count.\n* See commented program for explanation.\n```\nTime Complexity --> O(n ^ 2) // where n is the length of the array\nSpace Complexity --> O(n) // as we are using map to store pairs\nIt paases [ 60 / 60] in built test cases\n```\n\n**Code (C++)**\n```\nclass Solution {\npublic:\n    int findPairs(vector<int>& arr, int k) {\n        int n = arr.size(); // take the size of the array\n        int count = 0; // variable to store count\n        \n        sort(arr.begin(), arr.end()); // sort the array to find unique pairs\n        map<pair<int,int>, int> mp; // make a map where key is pair & value if it occurs\n        \n        for(int i = 0; i < n - 1; i++) // traverse from the whole array\n        {\n            for(int j = i + 1; j < n; j++)\n            {\n                if(abs(arr[j] - arr[i]) == k) // if it follows criteria\n                {\n                    // make a pair to find whether it is unique or not\n                    pair<int,int> p = {arr[i], arr[j]}; \n                    \n                     // if this pair not present in the map, then we do the computation\n                    if(mp.find(p) == mp.end())\n                    {\n                        count++; // increment count\n                        mp[p] = 1; // make its value as 1, saying that now it is present in our map\n                    }\n                }\n            }\n        }\n        return count; // and at last return the count\n    }\n};\n```\n__________________\n***Solution - II (Accepted)-***\n* So a question arises can we optimise it.\n* And answer is yes, but how?\n* See, *we have to find number of unique pairs such that their absoloute difference is k.*\n* suppose, **`a - b == k --> a = b + k`**\n* Can\'t we store all the values of array into a map and then `for every value we find value + k`.\n* That\'s all we have to do.\n* see commented code for more explanation.\n```\nTime Complexity --> O(n) // where n is the length of the array\nSpace Complexity --> O(n) // as we are using unordered map to store pairs\nIt paases [ 60 / 60] in built test cases\n```\n**Code (C++)**\n```\nclass Solution {\npublic:\n    int findPairs(vector<int>& arr, int k) {\n        int n = arr.size(); // take the size of the array\n        unordered_map<int, int> mp; // map to store all values of array\n        \n        for(int i = 0; i < n; i++) //store all values of array into map\n        {\n            mp[arr[i]]++;\n        }\n        \n        int count = 0; // variable to store the unique pairs\n        \n        if(k != 0) // if k is not zero\n        {\n            for(auto it = mp.begin(); it != mp.end(); it++) // traverse in all over the map\n            {\n                // if value + k is present in map\n                if(mp.find(it -> first + k) != mp.end())\n                {\n                    count++; // increment count\n                }\n            }\n        }\n        else // see for k = 0, we have to just find all the values greater than 1\n        {\n            for(auto it = mp.begin(); it != mp.end(); it++)\n            {\n                if(it -> second > 1)\n                {\n                    count++;\n                }\n            }\n        }\n        \n        return count; // at last return count\n    }\n};\n```\n---\n\n**SOLN - III**\n```\n1) Come back to problem after almost two years.\n2) Solved the same question with set only. \n3) Nothing more about the approach, insert all the elements into the set \nto count only single unique pairs.\n4) But for the case, when k == 0, we need to consider all the elements\nwhose frequency is greater than one. \n5) Also, we don\'t need to bother about their count as it dosen\'t matter.\n6) So, In process of inserting elements into the set, just check if this \nelement already exist into the set that means it\'s frequency is definately \ngoing to be greater than 1, so insert this into left out set.\n7) That\'s it, traverse the set and count the answer.\n8) Easy peasy, anyways, byyye....\n```\n\n***CODE***\n```\nint findPairs(vector<int>& nums, int k) {\n\n        set<int> s;\n\n        // in case k will be zero,\n        // We need to only count those elements whose frequency is\n        // greater than 1 \n        set<int> leftOutSet; \n\n        for(int i: nums) {\n\n            if(!s.count(i)) s.insert(i);\n            else leftOutSet.insert(i);\n        }\n\n        int ans = 0;\n        for(auto it: s) {\n            \n            int toFind = it + k;\n            if(s.count(toFind)) ans++;\n        }\n\n        return k == 0 ? leftOutSet.size() : ans;\n    }\n};\n\n```\n\n\n***`If u find this useful , please consider to give a upvote!!`***
['C']