Smallest Absolute Difference
Medium Accuracy: 36.61% Submissions: 3619 Points: 4

Given an array of size n containing positive integers n and a number k,The absolute difference between values at indices i and j is |a[i] – a[j]|. There are n*(n-1)/2 such pairs and you have to print the kth smallest absolute difference among all these pairs.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the array. Then next line contains n space separated integers forming the array. The last line contains the integer k.

Output:
Print the kth smallest absolute difference among all these pairs.

Constraints:
1<=T<=10^5
1<=N<=10^5
1<=a[i]<=10^5
1 <= k <= n*(n-1)/2

Example:
Input:

2
4
1 2 3 4
3
2
10 10
1

Output:
1
0

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.