Problem · Array
Min Amplitude
Learn this problemProblem statement
Given an Array A, find the minimum amplitude you can get after changing up to 3 elements. Amplitude is the range of the array (basically difference between largest and smallest element).
Function
minAmplitude(A: int[]) → intExamples
Example 1
A = [-1, 3, -1, 8, 5, 4]return = 2We can change -1, -1, 8 to 3, 4 or 5.
Example 2
A = [10, 10, 3, 4, 10]return = 0Change 3 and 4 to 10.
Constraints
1 ≤ A.length ≤ 2 * 10^5-10^9 ≤ A[i] ≤ 10^9- You may replace at most three array elements with arbitrary integer values.