← All problemsSign in

Remove the Peaks

CodeChefRating 3162Open on judge ↗

For an array $A$, an element $A_i$ $(1 \lt i \lt |A|)$ is said to be a *peak* if $A_i \gt A_{i-1}$ and $A_i \gt A_{i+1}$. Note that the first and last elements are never peaks. You are given a permutation $P$ of length $N$, and an empty set $S$. In one operation, you can do the following: - Remove an element $P_i$ such that $P_i$ is a *peak*, and insert it into the set $S$. Note that subsequen

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