This time, the exercises didn’t name a technique, so you had to pick one from the constraints. Making that choice is the skill this section trains. A working solution matters, and so does being able to say which detail of the problem pointed you toward it.
Here’s what each problem’s constraints suggested:
- Nearby Repeat: Only the distance to the most recent equal value matters. Storing each value’s latest index, or keeping just the last k values, answers that in one pass.
- Shared Ordered Readings: Sorted inputs let you walk both lists merge-style and advance past the smaller value. A counting dictionary finds the same values, but its extra storage breaks the required O(1) auxiliary space.
If you reached for hashing on the second problem, that’s a perfectly reasonable first idea! The sorted-input guarantee is the clue that a lighter approach exists.
Without a pattern name to lean on, a few false starts are part of the deal. Maybe you picked an approach, ran the tests, and then had to rethink the whole thing. That detour is worth remembering, because it shows you which constraint you read past. Pick the exercise that took you the most attempts, and in two or three sentences, explain what first went wrong and what changed your mind.