Nudge Every Item
Every item of nums has to be changed exactly once: you either add k to it or subtract k from it, and you choose which for each item on its own. The spread of a list is its largest item minus its smallest.
Return the smallest spread the list can have after all the changes.
Example 1
nums [2,9,4]
k 3
returns 2
Raise 2 and 4 to 5 and 7, and lower 9 to 6: the spread is 7 - 5 = 2.
Example 2
nums [3,11]
k 4
returns 0
Both items must move by 4. Raising 3 and lowering 11 makes them both 7.
Constraints
1 <= len(nums) <= 1000 <= nums[i] <= 100000 <= k <= 10000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.