Make Them Alike
You are given a permutation $P$ of length $N$, an array $A$ of size $N$, and an integer $M$. Initially, $0 \le A_i \le M$. Consider an array $A'$ obtained from $A$ by replacing all **zeros** in $A$ with **positive** integers **less than or equal to** $M$. The array $A'$ will then be transformed as follows, in $N$ steps: - In the $i^{th}$ step, we set $A'_i = A'_{P_i}$. The initial array $A'$
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.
Sign in to chat with the tutor and save your progress.
Sign in to start