Ehab and Prefix MEXs
MediumRating 1600CodeforcesConstructive Algorithms
Approach hintTry it first, then revealHide
Where a increases at position i, b[i] must be the previous value a[i-1]. Fill the remaining positions with the smallest numbers that never appear in a, which cannot disturb any prefix MEX.