Can it be zero? | Sololearn: Learn to code for FREE!

Can it be zero?

Well, I'm actually talking about the problem in the link below: 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.

10th Jun 2022, 4:16 PM
Avro Saha
Avro Saha - avatar
1 Resposta
+ 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.
10th Jun 2022, 5:36 PM
Denise Roßberg
Denise Roßberg - avatar