Problem
Ask
Submissions

Problem: Find K-th Smallest Pair Distance

Medium
30 min
Explore how to identify the kth smallest absolute difference between pairs in an integer array by applying sorting and search techniques. Understand problem constraints and practice implementing solutions using binary search and two-pointer methods.

Statement

Given an array of integers nums and an integer k, return the kthk^{th} smallest distance between any pair of integers (nums[i], nums[j]), where 00 \leq i << j << num.length.

The distance between a pair of integers, aa and bb, is defined as the absolute difference between them.

Constraints:

  • n==n == nums.length

  • 2n1032 \leq n \leq 10^3

  • 00 \leq nums[i] 103\leq 10^3

  • 11 \leq k n×(n1)2\leq \frac{n \times (n-1)}{2}

Note: Given an array of size nn, the total number of possible pairs is given by nC2{}^{n}C_{2}. As nC2{}^{n}C_{2} evaluates to n×(n1)2\frac{n \times (n-1)}{2}, there are exactly these much possible kk-distances.

Problem
Ask
Submissions

Problem: Find K-th Smallest Pair Distance

Medium
30 min
Explore how to identify the kth smallest absolute difference between pairs in an integer array by applying sorting and search techniques. Understand problem constraints and practice implementing solutions using binary search and two-pointer methods.

Statement

Given an array of integers nums and an integer k, return the kthk^{th} smallest distance between any pair of integers (nums[i], nums[j]), where 00 \leq i << j << num.length.

The distance between a pair of integers, aa and bb, is defined as the absolute difference between them.

Constraints:

  • n==n == nums.length

  • 2n1032 \leq n \leq 10^3

  • 00 \leq nums[i] 103\leq 10^3

  • 11 \leq k n×(n1)2\leq \frac{n \times (n-1)}{2}

Note: Given an array of size nn, the total number of possible pairs is given by nC2{}^{n}C_{2}. As nC2{}^{n}C_{2} evaluates to n×(n1)2\frac{n \times (n-1)}{2}, there are exactly these much possible kk-distances.