← All problemsSign in

Perfect Prefixes

CodeChefRating 2343Open on judge ↗

A permutation of length $N$ is an array of length $N$ that contains every integer from $1$ to $N$ exactly once. For example, $[1, 3, 2]$ and $[2, 1, 3]$ are permutations of length $3$, but $[2, 1, 2]$ and $[3, 4, 2]$ are not. The *beauty* of a permutation $P$ is defined to be the number of prefixes of $P$ that are themselves permutations. That is, it is the number of integers $i$ ($1 \leq i \

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