Count Pairs With Difference K

Given an integer array nums and a non-negative integer k, return the number of index pairs (i, j) such that i < j and abs(nums[i] - nums[j]) == k.

Given an integer array `nums` and a non-negative integer `k`, return the number of index pairs `(i, j)` such that `i < j` and `abs(nums[i] - nums[j]) == k`.

- `2 <= nums.length <= 100` - `-10^9 <= nums[i] <= 10^9` - `0 <= k <= 10^9`

Example 1: input nums = [1,3,1,5,4], k = 2; output 3. The qualifying index pairs hold values (1,3), (3,1), and (3,5).

Example 2: input nums = [2,2,2], k = 0; output 3. Each pair of equal positions has difference zero.

Category: Arrays & Hashing. Topic: arrays. Difficulty: Easy. Patterns: hashing.