← 返回 google 的题目列表Necklace Split with at Most Two Cuts (Equal D and R for Both People)
类型:online_judge
Problem
You are given a string s consisting only of 'D' and 'R', representing a necklace.
The entire necklace satisfies: count('D') == count('R').
Cut the necklace and split it between two people such that within each person’s share, the number of 'D' equals the number of 'R'.
Return any valid splitting plan with:
At most 2 cuts
After cutting, each person receives one or more contiguous segments induced by the cuts
The two shares are disjoint and cover all characters
For each person, across all received segments combined: #D == #R
You may output cut positions (between characters) plus the segment assignment, or directly output interval lists for each person.
Constraints
1 <= len(s) <= 2e5
Example (format illustration)
Input: s = "DRRD" Output could be: Person A gets [(0,1)] ("DR"), Person B gets [(2,3)] ("RD")