← All problemsSign in

Ayoub’s Game

Ayoub got bored, so he invented a game to be played on paper. He writes $n$ integers $a_1, a_2, ..., a_n$. Each of those integers can be either 0 or 1. He is allowed to do exactly one move: he chooses two indices $i$ and $j$ $(1 ≤ i ≤ j ≤ n)$ and flips all values $a_k$ for which their positions are in range $[i, j]$ (that is $i ≤ k ≤ j$). Flip the value of $x$ means to apply operation $x = 1 -

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