0
Can it be zero?
Well, I'm actually talking about the problem in the link below: https://www.geeksforgeeks.org/minimize-the-maximum-difference-between-the-heights/ Is it possible that the minimum height difference is zero? For instance, in the array {1, 3, 5} with B=2, 3 can be increased to 5 and 5 can be decreased to 3 which gives a minimum difference of zero.
1 Odpowiedź
+ 1
Yes it is possible that a difference is 0:
5 -> 3
1 -> 3
But the task is to minimize the maximum height.
In your case output should be 2.
1,3,5 after converting: 3,3,1 (or 3,3,5)
max difference = 2
Your approach to see where the difference becomes 0 is definitely correct. Ideally, after the conversion all numbers are equal, so that the maximum difference is 0.
Or, if this is not possible, the numbers must be as close as possible.