The question statement is as follows- Given an integer array, return the kth smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B.
The solution which leetcode accepts is the Binary Search + Prefix Sum Approach. But even after going through it more than 100 times, I am not able to figure it out.
Can someone guide me? Possibly with a dry run of an example and help me figure out how are we actually eliminating the search space using binary search? Please help me with an example as there are ample descriptive explanations on the internet
This is a LeetCode hard-tagged problem, you can see the explanations of various solutions here in this link:
Python
Java
C++