Problem 3948 · Medium

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.

Open the interactive visualisation