This question was asked in InterviewBit Academy Enterance Test on 16 Feb.
Given an array of integer A of size N. Minimize the absolute difference between maximum and minimum element of the array.
You can perform two types of operations atmost B times in total to change the values in the array. Multiple operations can be performend on the same element.
- Increment : A[i] \rightarrow A[i] + 1
- Decrement : A[i] \rightarrow A[i] - 1
Return the minimum difference possible.
Constraints
1 \leq N \leq 10^{5}
1 \leq A[i] \leq 10^{6}
1 \leq B \leq 10^{9}
Help. How to approach.