532. K-diff Pairs in an Array

Practice K-diff Pairs in an Array for free on NudgeCode: Medium, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return the number of unique k-diff pairs in nums. A k-diff pair is a pair of values (nums[i], nums[j]) with i != j and |nums[i] - nums[j]| == k. Pairs are counted by their values, so (1, 3) and (3, 1) are the same pair and repeated values don't create new pairs.

Example

nums = [3,1,4,1,5], k = 2  ->  2     ((1,3) and (3,5))
nums = [1,2,3,4,5], k = 1  ->  4
nums = [1,3,1,5,4], k = 0  ->  1     ((1,1))

Constraints