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

**Example:** [1,5,8,10], k=25.

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

Open in the Dojo editor