← All problemsSign in

Valleys and Hills

CodeChefRating 1635Open on judge ↗

Chef built a binary string $S$ that has exactly $N$ hills and $M$ valleys. - A **hill** is any index $1 \lt i \lt |S|$ such that both its neighbors are strictly smaller than it, i.e, $S_{i-1} \lt S_i$ and $S_{i+1} \lt S_i$. - A **valley** is any index $1 \lt i \lt |S|$ such that both its neighbors are strictly larger than it, i.e, $S_{i-1} \gt S_i$ and $S_{i+1} \gt S_i$. Chef thinks that his st

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