← All problemsSign in

Front or Back

CodeChefRating 1622Open on judge ↗

There were $N$ people lined up in a queue. The people are numbered $1$, $2$, $\ldots$, $N$ but not necessarily in the order they are lined up. Unfortunately, some of them can't even understand where the front of the queue is. So, some people are looking towards the front of the queue and some people are looking towards the back of the queue. The $i$-th person reports $A_i$ as the number of peop

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