1. You are given an array of N elements.
2. You are also given a number K.
3. You have to find the Kth smallest distance among all the pairs in the array.
4. The distance of a pair (u, v) is defined as the absolute difference between u and v.
5. For example:
Input:
arr = [1,3,1]
K = 1
Output: 0
Explanation:
Here are all the pairs:
(1,3) -> 2
(1,1) -> 0
(3,1) -> 2
Then the 1st smallest distance pair is (1,1), and its distance is 0.
6. display is a utility function, feel free to use it for debugging purposes.
7. main takes input from the users and creates the array.
8. This is a functional problem.
9. You have to complete the smallestDistancePair function. It takes as input an array and K. It should return the Kth smallest distance.
10. Don't change the code of main and display.
Input Format
First line takes input N, the length of the array. Second line takes input N space separated numbers representing the elements of the array. Third line takes input K. Input is handled for you.
Output Format
Kth smallest pair distance. Output is handled for you.
Constraints
2 <= N <= 10000 1 <= K <= N*(N-1)/2
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
3 1 3 1 1
Output
0