Skip to content

Practice Minimize the Maximum Adjacent Element Difference

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3357
LeetCode Problem

Minimize the Maximum Adjacent Element Difference

Problem Statement

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.

Source: Minimize the Maximum Adjacent Element Difference on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,-1,10,8]
Output
4

# Example 2

Input
nums = [-1,-1,-1]
Output
0

# Example 3

Input
nums = [-1,10,-1,8]
Output
1

Constraints

2 <= nums.length <= 10^5
nums[i] is either -1 or in the range [1, 10^9].

Related LeetCode Problems

Practice more problems similar to Minimize the Maximum Adjacent Element Difference.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.