Restore Sequence
Alice has a very complex machine ― when fed with a sequence $A_1, A_2, \ldots, A_N$, it produces a sequence $B_1, B_2, \ldots, B_N$, where for each valid $i$, $B_i$ is the largest index $j$ such that $A_i$ divides $A_j$ (since $A_i$ divides itself, such an index always exist). For example, if the machine is fed with $A = [2, 6, 5, 3, 4]$, it produces $B = [5, 2, 3, 4, 5]$. Alice gave you a sequen
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