← All problemsSign in

Restore the Permutation

CodeChefRating 3037Open on judge ↗

Given a permutation $P$ of size $N$, an array $A$ of size $N$ can be generated using the following method: - If $P_i\gt P_j$ for all $(1 \leq j \lt i)$, set $A_i=0$; - Otherwise, set $A_i = max(j)$ where $(1 \leq j \lt i)$ and $(P_j \gt P_i)$. Unfortunately, we lost the permutation $P$ and some elements of the array $A$. The lost elements of the array $A$ are denoted as $A_i = -1$. These eleme

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