← All problemsSign in

D - Make Empty

You are given a permutation $p$ of $[1, 2, \ldots, n]$. It is guaranteed that $n$ is even. You can perform the following operation: - Select a subsequence $^\dagger$ (say $t$) of length $2k$ ($k$ may vary between operations) such that either $\max(t_1, t_2, \ldots, t_k) < \min(t_{k+1}, t_{k+2}, \ldots, t_{2k})$ or $\min(t_1, t_2, \ldots, t_k) > \max(t_{k+1}, t_{k+2}, \ldots, t_{2k})$.

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