
Given:- ‘X’ = 5 and ‘N’ = 2.
‘POS’[] = 3, 4
The output will be 3 and 3.
Initially, there are no lights, and we install a light at position three; therefore, there is a segment between the 3 and 6.
Then we install a light at position four; therefore, the largest gap becomes between 0 to 3.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains two space-separated integers, 'X' and ‘N’, where ‘X’ is the length of the road and ‘N’ is the number of lights.
The next line contains ‘N’ space-separated integers denoting the position of the ith light.
For each test case, print a single line containing a single integer denoting the maximum gap for every light we install.
The output of each test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 2000
1 <= X <= 10 ^ 8
1 <= POS[i] <= X
Where ‘T’ is the total number of test cases, ‘N’ is the number of lights we install, ‘X’ is the length of the road, and ‘POS[i]’ denotes the position of the 'i th' light.
Time limit: 1 sec.
The main idea is to use a set ‘LIGHTS’ and a multiset ‘DISTANCE’ to maintain the position of light and distance maintains all the distances. For a given position, find the next position of the light and the previous position of the light, and put it into the ‘DISTANCE’ set, and the end of the set contains the answer since the values are always sorted in increasing order.
The main idea is to maintain an array of sorted points and then, for each query, find the lower bounded value from the actual array of points.