Kth smallest distance

Write codeHard30 minGoogle style

Your task

Given an integer array nums, define the distance of a pair (i, j) as abs(nums[i] - nums[j]). Return the k-th smallest distance among all n*(n-1)/2 pairs (1-indexed). 2 <= len(nums) <= 1e4 so enumerating all pairs is too slow.

Examples

smallest_distance_pair(nums: list[int], k: int) -> int
Example 1
Inputsmallest_distance_pair([1, 3, 1], 1)
Output0