THOUGHTWORKS INDIA | Off Campus Online Assessment Question (2023) | Count of Pairs With Absolute Difference K
Question · Posted Jun 2026
Problem Statement You are given an integer array nums and an integer k. Return the number of pairs (i, j) such that: i < j |nums[i] - nums[j]| = k In other words, count all pairs whose absolute difference is exactly k. Input Format Integer array nums Integer k Example 1 Input: nums = [1,2,2,1] k = 1 Output: 4 Explanation Valid pairs are: (1,2) (1,2) (2,1) (2,1) Total = 4 pairs. Example 2 Input: nums = [1,3] k = ...
The full answer & interview discussion are available to premium members.
Log in Create a free account