The part that tripped me up wasn't the sliding window, it was the verbal justification.
Model the circular string as a sequence of +1 (for 'D') and -1 (for 'R') values, and use prefix sums to identify cut positions where the cumulative sum returns to zero. The problem reduces to finding two cut points that partition the circle into two segments each with sum zero, which is always possible due to the balanced nature of the string.
Pro tip: Start by clarifying that the two pieces are contiguous arcs of the circle, and mention that the proof of sufficiency relies on the intermediate value theorem applied to the prefix sum function around the circle.
Convert the string into a numeric array where 'D' = +1 and 'R' = -1, and note that the total sum is zero because counts are equal.
Compute the prefix sum around the circle, treating it as a periodic function with period n, and identify points where the sum equals zero.
Choose any cut point where the prefix sum is zero; this ensures one piece (the arc between cuts) has balanced D's and R's.
From the first cut, traverse the circle and find another point where the prefix sum returns to zero, which must exist because the total sum is zero and the function is continuous in discrete steps.
Explain that two cuts always suffice because the prefix sum function must cross zero at least twice (including the start/end) due to its periodic nature and zero total sum.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.