Given an array of integers, find the kth smallest absolute difference between any two elements in the array.
Explanation: The absolute differences are |17-23| = 6, |17-29| = 12, |17-31| = 14, |23-29| = 6, |23-31| = 8, |29-31| = 2. The 3rd smallest absolute difference is 6.
Explanation: The absolute differences are |5-8| = 3, |5-12| = 7, |5-18| = 13, |8-12| = 4, |8-18| = 10, |12-18| = 6. The 2nd smallest absolute difference is 4.
Find kth order statistic using heap
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak