Description
Given an integer array nums, find the kth smallest distance among all pairs. The distance of a pair (a, b) is the absolute difference |a - b|.
Examples
Input:
nums = [1,3,1], k = 1Output:
0Explanation:
Pairs: (1,3)=2, (1,1)=0, (3,1)=2. Smallest is 0.
Input:
nums = [1], k = 1Output:
1Explanation:
Edge case with a single-element array.
Input:
nums = [1,6,1,4], k = 3Output:
3Explanation:
All pairs and their distances: (1,6)=5, (1,1)=0, (1,4)=3, (6,1)=5, (6,4)=2, (1,4)=3. Sorted distances: [0,2,3,3,5,5]. The 3rd smallest is 3.
Constraints
- •
2 ≤ nums.length ≤ 10⁴