Lexicographically Maximum MEX Array
Cut the array into consecutive segments and record each segment’s mex. Grab the largest mex the remaining suffix can reach, using the shortest segment that achieves it.
Cut the array into consecutive segments and record each segment’s mex. Grab the largest mex the remaining suffix can reach, using the shortest segment that achieves it.