← All problemsSign in

Counting MEX Is Fun

CodeChefRating 1929Open on judge ↗

For a sequence $B$, the MEX (minimum excluded value) of $B$, denoted as $MEX(B)$, is the smallest non-negative integer that does not appear in $B$. You are given two integers $N$ and $K$. Consider all permutations $P$ of the integers {$0, 1, ..., N-1$}. For a permutation $P$, define a set $S(P)$ containing all distinct MEX values of all its subarrays. Formally, $S(P)$ = { $MEX(P[l..r]) |

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start