3948. Lexicographically Maximum MEX Array
You are given an integer array
nums.You want to construct an array
resultby repeatedly performing the following operation untilnumsbecomes empty:
- Choose an integer
ksuch that1 <= k <= len(nums).- Compute the MEX of the first
kelements ofnums.- Append this MEX to
result.- Remove the first
kelements fromnums.Return the lexicographically maximum array
resultthat can be obtained after performing the operations.The MEX of an array is the smallest non-negative integer not present in the array.
An array
ais lexicographically greater than an arraybif in the first position whereaandbdiffer, arrayahas an element that is greater than the corresponding element inb. If the firstmin(a.length, b.length)elements do not differ, then the longer array is the lexicographically greater one.
1 | class Solution { |