Skip to content

Practice K-diff Pairs in an Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#532
LeetCode Problem

K-diff Pairs in an Array

Problem Statement

Count unique value pairs drawn from two different indices in nums whose absolute difference is k. Repeated occurrences of the same pair count once. When k is zero, a value qualifies only if it occurs at least twice.

Source: K-diff Pairs in an Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

# Example 3

Input
nums = [1,3,1,5,4], k = 0
Output
1

Constraints

1 <= nums.length <= 10^4
-10^7 <= nums[i] <= 10^7
0 <= k <= 10^7

Related LeetCode Problems

Practice more problems similar to K-diff Pairs in an Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.