Twitter Online Assessment (OA) - K-different Pairs in an Array

Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array. A k-diff pair is an integer pair (nums[i], nums[j]), where both of the following are true:

  1. 0 <= i < j < nums.length
  2. |nums[i] - nums[j]| == k

Note: |x| is the absolute value of x.

Examples

Example 1:

Input: nums = [3,1,4,1,5], k = 2

Output: 2

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro