Input: arr[] = {1, 1, 1}
Output: 0
Explanation: Since, all the numbers are equal, so there is no need to perform any operation.
The minimum difference would be 0.
Input: arr[] = {2, 2, 3, 1}
Output: 0
Explanation: Take i = 2 and j = 3, arr[2] = 3 - 1 = 2, arr[3] = 1 + 1 = 2.
The array becomes, [2, 2, 2, 2]. The difference = 0.
Input: arr[] = {1, 2, 3, 4, 4, 1}
Output: 1
Explanation: In this case, 2 operations can be performed making the final array
arr[] = [2, 2, 3, 3, 3, 2].The difference would be 1.
Notice this is the minimum difference produces it can't be less than 1.
- Take i = 1, j = 3, array becomes, [2, 2, 3, 3, 4, 1]
- Take i = 5, j = 4, array becomes, [2, 2, 3, 3, 3, 2]