nums
.minScore
as the difference between the last and first elements after adding k
to the first and subtracting k
from the last.i
, calculate the high as the maximum of nums[i] + k
and nums[-1] - k
.
b. Calculate the low as the minimum of nums[i+1] - k
and nums[0] + k
.
c. Update minScore
with the minimum of the current minScore
and high - low
.minScore
.