Minimize the Maximum Adjacent Element Difference
You are given an array of integers nums. Some values in nums are missing and are denoted by -1.
You must choose a pair of positive integers (x, y) exactly once and replace each missing element with either x or y.
You need to minimize the maximum absolute difference between adjacent elements of nums after replacements.
Return the minimum possible difference.
Example 1
Input
nums = [1,2,-1,10,8]Output
4Choosing
(6, 7) allows nums to become [1, 2, 6, 10, 8], whose maximum adjacent absolute difference is 4.Example 2
Input
nums = [-1,-1,-1]Output
0Choosing
(4, 4) allows nums to become [4, 4, 4], so every adjacent absolute difference is 0.Constraints
- 2 <= nums.length <= 10^5
- nums[i] is either -1 or in the range [1, 10^9].