Counting Pairs

Problem Overview

  • Count distinct integer pairs (a, b) in an array where a + k = b; pairs are distinct by element identity.
  • Input: numbers[n] and integer k; Output: an integer count; Constraints: 2 ≤ n ≤ 2e5, values and k up to 1e9.
  • Applies to array pair-difference checking in data processing; elements in a pair may be the same item when k = 0.
  • Asked in Amazon interviews; a classic coding interview problem and interview question on counting pairs.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: