Alex is on a company-sponsored tour and wants to visit several places. The distances of the places are given in the form of an array of integers. The driver told him that he can only take him to a specific number of places as per the company policy, so he tells Alex the allowed number of places he can visit, lets call it
n. Alex decides to create a list of places of length
n call that array
arr x, where the distance between the place farthest to Alex (max) and the distance between the place closest to Alex (min) is minimum.
The minimum difference between max and min of an array is calculated as:
Top arr x - Bottom arr x
?? Top denotes the farthest place in arr x. ?? Bottom denotes the closest place in arr x.
NOTE: Integers an array may not be unique.
Write a function
solve that have the following parameters. It must return an integer indicating the minimum possible unfairness.
1.) a = The number of elements to choose
2.) arr[x] = An array of integers
a = 4
arr[x] = [1, 2, 3, 4, 5] Output:
a = 4
selecting 4 integers 1,2,3,4.
Unfairness equals top(1,2,3,4) - bottom(1,2,3,4) = 4 - 1 = 3.
x] will be greater than 0 and less than 10000.