Pairs with difference k
Your task
Given an integer array nums and an integer k (k >= 0), return the number of UNIQUE pairs of distinct array positions whose values differ by exactly k. A pair is identified by its value pair, so (1,3) counts once even if 1 or 3 repeats. For k = 0, count values that appear at least twice. Array length up to 1e4.
Examples
count_pairs_diff(nums: list[int], k: int) -> intExample 1
Input
count_pairs_diff([3, 1, 4, 1, 5], 2)Output
2