FastPrepMinimum Operations to Make an Array Continuous
Problems/Minimum Operations to Make an Array Continuous

Minimum Operations to Make an Array Continuous

Amazon logoAmazon● HardNEW GRADONSITE INTERVIEW
QuestionFunctionExamples

Problem statement

Source note: The judged task matches the named standard continuous-array problem at about 99%. The statement supplies a portable function interface.

You are given a non-empty integer array nums of length n. In one operation, you may replace any one element with any integer.

An array is continuous when both conditions hold:

  • All n elements are unique.
  • The difference between the maximum and minimum elements is exactly n - 1.

Return the minimum number of replacement operations needed to make nums continuous.

Function

minOperations(nums: int[]) → int

Examples

Example 1

nums = [4,2,5,3]return = 0

The values are already the unique consecutive set {2,3,4,5}.

Example 2

nums = [1,2,3,5,6]return = 1

Replace 1 with 4 to obtain the continuous set {2,3,4,5,6}.

Example 3

nums = [1,10,100,1000]return = 3

At most one existing value can be retained inside any interval containing four consecutive integers, so three elements must be replaced.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int minOperations(int[] nums) {
      // write your code here
    }
}
Checking account…