442. Dota2 Senate
Two parties sit in the Dota2 senate: Radiant and Dire. The string senate gives the senators in speaking order, 'R' for a Radiant member and 'D' for a Dire member.
Voting runs in rounds. Senators take turns in the original order; a senator who has been banned is skipped. On their turn, a senator bans one senator of the opposing party — and if at that moment no opponents remain anywhere, their own party instead declares victory and the game ends. After the last position, the next round starts again from the top, keeping the same order. Every senator plays the strategy that is best for their own party.
Your function receives the string senate and returns the name of the winning party: "Radiant" or "Dire" (exactly that capitalization).
Example 1:
Input: senate = "RD"
Output: "Radiant"
Explanation: The first senator (Radiant) bans the only Dire senator. When the second round reaches the Radiant senator again, no opponents are left, so Radiant declares victory.
Example 2:
Input: senate = "RDD"
Output: "Dire"
Explanation: The Radiant senator bans the first Dire senator, but the second Dire senator then bans the Radiant one. Only Dire remains, so Dire wins.
Constraints:
- 1 ≤ senate.length ≤ 10⁴
- senate[i] is either 'R' or 'D'.
Hints:
Greedy: the most dangerous opponent is the one who speaks soonest — banning anyone else lets that opponent ban one of your teammates first. So each senator should always ban the next opposing senator in speaking order.
Keep two queues holding the speaking positions of each party. Compare the two front positions: the smaller one speaks first, bans the other front, and re-enters their own queue with position + n, which schedules them for the next round. When a queue empties, the other party wins.
▶ Run checks these sample cases. Submit also runs hidden edge cases.
Input: senate = "RD"
Expected output: "Radiant"