Eleven problems for the one-pass search. Each is the lesson's loop with a different test or a different thing remembered. Decide before you type: first match or last? stop at the match, or keep going? what if there is none?
- The Final Log Entry: the last occurrence — no
break. - The Breaking Point and First Above Threshold: the first element strictly above k.
- Twin Signals: the first
iwitha[i] == a[i + 1]; the loop stops one short of the end. - First Local Peak: a test that looks at both neighbours, so
iruns from 1 to n − 2. - The Closest Match and Closest Value: keep the best so far and its index;
a strict
<keeps the first of equals. Closest Value prefers the smaller value on a tie — compare the pair{distance, value}— and its numbers reach 10¹⁸. - First Occurrence and Last Occurrence: 5·10⁶ numbers; keep the fast-IO
lines and read into a
vector<int>. - In Subarray: the search runs from
ltor(1-indexed in the statement). - Matrix Position: a search over a grid, row by row, stopping at the first
hit —
breakout of both loops, or return from a function.