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
More Atlassian problems
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024