K-diff Pairs in an Array

Medium

Description

Given an array of integers nums and integer k, return the number of unique k-diff pairs in the array. A k-diff pair has absolute difference k.

Examples

Input:nums = [3,1,4,1,5], k = 2
Output:2
Explanation:

(1,3) and (3,5).

Input:nums = [1,1,1,2,2], k = 1
Output:1
Explanation:

Only one unique pair (1,2) has absolute difference of 1. Even though there are multiple 1's and 2's in the array, only count unique pairs once.

Input:nums = [2,4,6,8,10], k = 3
Output:0
Explanation:

No pairs in the array have an absolute difference of 3. The differences between adjacent elements are all 2, and other pairs have differences of 4, 6, or 8.

Constraints

  • 1 ≤ nums.length ≤ 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!