dsa · medium
Minimize the Heights II
GreyOrangeArrayGreedySorting
For each tower height you may add k or subtract k (result may be 0 but not negative). Return the minimum possible difference between the tallest and shortest **after** the changes.
Arguments
arr— the input arrayk— you may addkor subtractkfrom each tower height
**Example:** [1,5,8,10], k=2 → 5.
Constraints
1 <= n <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,5,8,10] 2 Expected: 5