← All problemsSign in

Prefix Max Counting

CodeChefRating 2331Open on judge ↗

For a permutation $P$, we define $f(P)$ to be it's prefix max array, i.e. $f(P)_i = \max(P_1, P_2, \ldots, P_i)$. Now, you are given a partially filled in permutation $P$ of the integers $[1, N]$, i.e. some elements are $-1$. You want to replace the $-1$ elements with integers in $[1, N]$ to make it a permutation. What are the total number of distinct $f(P)$ possible? Since the answer may be la

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