When numbers wrap around, you need special arithmetic to compute distances. The pattern works for any ring: clocks, game boards, or circular arrays.
You store all tasks in a vector and process them one by one, maintaining state between iterations. This pattern (process list, update state, accumulate result) appears in many problems.
You learned to break complex conditions into simple cases. Instead of trying to handle everything at once, you check: is the target ahead or behind? Each case has its own formula. Clear cases mean clear code.