Maximum MEX by Decreasing Values
Updated
Problem statement
You are given an integer array arr. One operation replaces any element arr[i] by an integer x satisfying 0 <= x <= arr[i]. You may perform any number of operations.
The MEX of an array is the smallest nonnegative integer absent from it. Return the maximum MEX achievable after these operations.
Function
getMaximumMEX(arr: int[]) → intExamples
Example 1
arr = [3,2,3]return = 3Each element can supply any nonnegative number no greater than its original value. Build the longest prefix of distinct values starting at 0.
Example 2
arr = [0,1,1,3]return = 3Each element can supply any nonnegative number no greater than its original value. Build the longest prefix of distinct values starting at 0.
Example 3
arr = [0,0,0]return = 1Each element can supply any nonnegative number no greater than its original value. Build the longest prefix of distinct values starting at 0.
Constraints
1 <= arr.length <= 2 * 10^50 <= arr[i] <= 10^9
More IMC Trading Online Assessment questions
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
- Choose ContainersOA · Seen Aug 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Can Every Package Fit in a BoxOA · Seen Jul 2026
Similar questions at other companies
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Maximize Center A Package BenefitAmazon · OA
- EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions