FastPrepPossible MEX Values After One Optional Increment

Possible MEX Values After One Optional Increment

Citadel logoCitadel● MediumFULLTIMEOA
Learn

Problem statement

Given an array values of length n, each value is between 0 and n - 1. You may leave the array unchanged, or choose one element smaller than n - 1 and increment it by exactly one.

Return every distinct MEX that can result, in increasing order. The MEX is the smallest non-negative integer absent from the array.

Function

possibleMexValues(values: int[]) → int[]

Examples

Example 1

values = [0,1]return = [0,2]

Leaving the array unchanged gives MEX 2; incrementing the only 0 gives MEX 0.

Example 2

values = [0,0,1,3]return = [1,2]

MEX 2 is unchanged, while incrementing the unique 1 removes the last 1 and gives MEX 1.

Constraints

  • 1 <= values.length <= 200000
  • 0 <= values[i] < values.length

More Citadel problems

See Citadel hiring insights
public int[] possibleMexValues(int[] values) {
    // Write your code here.
}
values[0,1]
expected[0,2]
Checking account…