✅ Well Explained || Two Easy Solutions ✅
First Approach : Using HashMap\n\n1. First we will create map for counting frequencies of each element in the array.\n2. Now we have 2 cases over here as \n    
**First Approach : Using HashMap**\n\n1. First we will create map for counting frequencies of each element in the array.\n2. Now we have 2 cases over here as \n    -->a) if k == 0 it means we need to count frequency of the same element by using map.get(i) method.\n\t-->b) we need to take counter approach for every element by adding k everytime and check whether that element is present in map or not.\n3. Instead of iterating through array, we will iterate through map.keySet() for getting unique elements.\n\t\n\t\t// O(n) Time Solution\n\t\n\t\tclass Solution {\n\t\t\t\tpublic int findPairs(int[] nums, int k) {\n\t\t\t\t\tMap<Integer, Integer> map = new HashMap();\n\t\t\t\t\tfor (int num : nums)\n\t\t\t\t\t\tmap.put(num, map.getOrDefault(num, 0) + 1);\n\n\t\t\t\t\tint result = 0;\n\t\t\t\t\tfor (int i : map.keySet())\n\t\t\t\t\t\tif (k > 0 && map.containsKey(i + k) || k == 0 && map.get(i) > 1)\n\t\t\t\t\t\t\tresult++;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t}\n\n**Second Approach : Using HashSet**\n\n1. First sort the array.\n2. After that, iterating through loop from first element to the last element.\n3. Using BinarySearch, checked whether (nums[i] + k) is present in the array from index i+1 to n....i.e. if it is present we can take it as for counting approach.\n\t\t\n\t\tArrays.binarySearch(array_name, start_index, end_index, value_for_checking) ==> this method returns index of value which we are searching.\n\t\t\n4. After that just added minimum element to set for getting unique pairs as we know set contains only unique values.\n \n\t\t// O(nlogn) Time Solution\n\n\t\tclass Solution {\n\t\t\tpublic int findPairs(int[] nums, int k) {\n\t\t\t\tSet<Integer> uniquePair = new HashSet();\n\t\t\t\tArrays.sort(nums);\n\t\t\t\tint n = nums.length;\n\n\t\t\t\tfor (int i = 0; i < n - 1; i++)\n\t\t\t\t\tif (Arrays.binarySearch(nums, i + 1, n, nums[i] + k) > 0)\n\t\t\t\t\t\tuniquePair.add(nums[i]);\n\n\t\t\t\treturn uniquePair.size();\n\t\t\t}\n\t\t}\n**UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0\uD83C\uDF38), If you have any question, feel free to ask.**
['Binary Search', 'Sorting', 'Java']