Back to questions

Min Amplitude Google Python Interview Question

Min Amplitude

Google Python Interview Question

Given an integer array , the difference between the largest and smallest values is called amplitude. If you can change up to three elements of the array to any value, return the minimum possible amplitude.

Examples:

Example 1:

Input: arr = [4, -8, -1, 3, 7, 10, 5]

Output: 4

Explanation: By changing -8 and -1 to 3, and 10 to 7, the array can be transformed into [4, 3, 3, 3, 7, 7, 5]. The new maximum value is 7 and the new minimum value is 3, resulting in an amplitude of 7 - 3 = 4.

Example 2:

Input: arr = [3, 5, 10, 0]

Output: 0

Explanation: We can change 3, 5, and 10 to 0, resulting in the array [0, 0, 0, 0]. Since all values are the same, the maximum and minimum values are both 0, leading to an amplitude of 0 - 0 = 0.

Input

Python

Output