Search⌘ K
AI Features

Solution: K-diff Pairs in an Array

C# solution for the K-diff Pairs in an Array problem using the Two Pointers pattern.

Statement

Given an integer array nums and an integer k, return the number of unique pairs of values (a, b) such that a and b both appear in nums and |a - b| = k.

A pair is considered unique based on its values, not on the indices where those values occur in nums.

Note: When k = 0, a valid pair requires a value to appear at least twice in nums.

Constraints:

  • 11 \leq nums.length 104\leq 10^4

  • ...