Problem · Array

Min Amplitude

Learn this problem
EasyGoogleFULLTIMEOA
See Google hiring insights

Problem 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[]) → int

Examples

Example 1

A = [-1, 3, -1, 8, 5, 4]return = 2
We can change -1, -1, 8 to 3, 4 or 5.

Example 2

A = [10, 10, 3, 4, 10]return = 0
Change 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.

More Google problems

drafts saved locally
public int minAmplitude(int[] A) {
  // write your code here
}
A[-1, 3, -1, 8, 5, 4]
expected2
checking account