Search⌘ K
AI Features

Solution: Find K-th Smallest Pair Distance

Explore how to determine the k-th smallest distance between pairs in a sorted array using a combination of binary search and the sliding window technique. Understand how sorting the array and applying two pointers can efficiently count valid pairs and narrow search ranges, equipping you with strategies to solve similar coding challenges effectively.

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] ...