Facebook Pixel

Google Online Assessment (OA) 2021 | Minimum Amplitude

We define the "amplitude" of a list of integers as the largest value minus the smallest value in the array.

Now, given a list of integers, find the minimum amplitude of this list when up to 3 of its entries are replaced.

Parameter

  • entries: A list of integers of size n.
  • max_replacement: The maximum number of replacements of entries. For this question this will always be 3, but you should use this to help you write code that works for more cases.

Result

  • The minimum amplitude of this list when up to 3 of its entries are replaced.

Examples

Example 1:

Input: entries = [-1, 3, -1, 8, 5, 4]

Output: 2

Explanation: We can change -1, -1, 8 into either 3, 4, 5 to get the minimum amplitude.

Example 2:

Input: entries = [10, 10, 3, 4, 10]

Output: 0

Explanation: We can change 3, 4 into 10 to get the minimum amplitude.

Constraints

  • 1 <= n <= 1000
  • -10^9 <= entries <= 10^9

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro