← All problemsSign in

E - Merging Maximum

You're given a permutation $p$ of $\{1, 2, \ldots, n\}$. That is, $p$ is an array of length $n$ containing every integer from $1$ to $n$ exactly once each. You can perform the following operation on it: - Choose an index $i$ ($1 < i < |p|$). Here, $|p|$ denotes the current length of $p$. - Set $p_i = \max(p_{i-1}, p_i, p_{i+1})$. - Delete $p_{i-1}$ and $p_{i+1}$ from $p$. The remaining elemen

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