Official

E - Mex Min Editorial by en_translator


The answer is the minimum non-negative integer \(i\) such that there are no consecutive \(M\) elements in \(A\) that does not contain \(i\) at all.

Define
\(\mathrm{pos}_i\): an array of \(j\) such that \(A_j = i\), in the increasing order
beforehand, then check if there exists \(j\) such that \(\mathrm{pos}_{i, j} - \mathrm{pos}_{i, j - 1} > M\) in the increasing order of \(i\). Be careful of the both ends though; you should process separately, or add \(0\) and \(N + 1\) to \(\mathrm{pos}\) beforehand.
The overall time complexity is \(O(N)\).

posted:
last update: