Pair Difference Count

Hashmap Array Pair Algorithm Easy

Problem: Pair Difference Count

On this day, as we celebrate historical breakthroughs and clever problem-solving, your task is to use hashmap techniques to solve the following challenge:

Given an array of integers and an integer k, write a function to determine the number of unique pairs in the array that have an absolute difference equal to k.

Details:

  • A pair (a, b) is unique and should be counted only once regardless of order (i.e., (a, b) is the same as (b, a)).
  • An integer can participate in multiple pairs, but each unique pair should only be counted once.

Example:

For array = [3, 1, 4, 1, 5] and k = 2, there are two pairs: (1, 3) and (3, 5).

Input:

  • A list/array of integers
  • An integer k

Output:

  • An integer representing the total number of unique pairs with an absolute difference of k

Function Signature Example (Python):

def count_pair_difference(nums: List[int], k: int) -> int:
    # Your code goes here

Use hashmap techniques to achieve an efficient solution.