Trains the technique from
LeetCode 3948Lexicographically Maximum MEX ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A conveyor carries bins in a fixed order. Bin i holds a token stamped with the whole number nums[i].
The MEX of a collection of tokens is the least non-negative integer that no token in the collection carries. So a collection with no 0 has MEX 0, and a collection holding 0 and 1 but no 2 has MEX 2.
You cut the conveyor into consecutive groups: every bin lands in exactly one group, no group is empty, and the groups keep conveyor order. The report of a cut is the list of the MEX values of its groups, in the same order as the groups.
Return the largest report under this comparison: compare two reports at the first position where they differ, and the one with the bigger value there is larger; if neither differs anywhere and one is shorter, the longer report is larger. Any number of groups from one up to nums.length is allowed.
Example 1
Cutting after the fifth bin gives the groups `[5,0,3,1,2]` and `[0]`. The first group misses 4 and carries everything below it, so its MEX is 4; the second group carries 0 and misses 1, so its MEX is 1.
Example 2
The groups are `[0,2,1]`, `[0]` and `[0]`, with MEX values 3, 1 and 1. Every bin sits in exactly one group and the order is kept.
Example 3
No bin carries 0, so any group at all has MEX 0. Splitting into two single-bin groups gives a report of two zeros, which beats the shorter report `[0]` from a single group.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum_m_e_x(nums: list[int]) -> list[int]:public int[] maximumMEX(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.