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.


Example 1:

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

Output: 2

Try it yourself




Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions