Alice has a collection of numbers. She would like to place them on a number line. She places each of the numbers on the point corresponding to its value on the number line. Now she wonders, what's the size of the smallest interval on the number line such that there are at least numbers from her collection on that interval?
The first line of the input contains two integers () and (). The next line consists of space separated integers denoting Alice's numbers. Let, () be the number on this line.
In a single line, print the size of the smallest interval on the number line where at least integers from Alice's collection can be found.
5 3 17 12 5 4 8
The desired interval is [4,8] which contains 4, 5 and 8. The size of this interval is 4.
6 2 16 5 7 4 4 8
The desired interval is [4,4] which contains 4 and 4. The size of this interval is 0.
Login to submit
Sort the array in non-decreasing order. Now notice that, the smallest interval that starts at ai and...