Problem · Array
Maximum MEX
Learn this problemProblem statement
Given an array arr of non-negative integers and a positive integer x, one operation adds x to or subtracts x from any array element. You may perform any number of operations.
The MEX is the smallest non-negative integer not present in an array. Return the maximum MEX that can be achieved.
Function
maximumMEX(arr: int[], x: int) → intExamples
Example 1
arr = [0,1,2,1,3]x = 3return = 5Add 3 to one occurrence of 1. The array can contain every value from 0 through 4, so its MEX is 5.
Example 2
arr = [1,3,4]x = 2return = 2Subtract 2 twice from 4 to create 0. The value 2 cannot also be created from the remaining residues.
Constraints
1 <= arr.length <= 1000000 <= arr[i] <= 10^91 <= x <= 100000