#3357

Minimize the Maximum Adjacent Element Difference

hard · 19.6% accepted · 63 likes · top 1%

array · binary search · greedy

⊣ practice⊣ open on leetcode ↗

Description

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.

Solution