Maximum MEX
Updated
Problem 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 Online Assessment questions
- 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
- Binary Search Tree IteratorOA · Seen Nov 2023
- Binary Tree Level Order TraversalOA · Seen Nov 2023
Similar questions at other companies
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Task Scheduler with CooldownGoDaddy · OA
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Get Triplet CountIBM · OAIBM interview questions
- Minimum Values with Even Powers of TwoVisa · OAVisa interview questions
- Resource AllocationMaven Securities · OAMaven Securities interview questions