nums array.nums array and populate the HashMap with the frequency of each number.count to store the number of valid pairs.nums array again.k units less (num - k) is in the HashMap and add its frequency to count.k units more (num + k) is in the HashMap and add its frequency to count.count by 2 before returning it.