In the world of Dota2, there are two parties: the Radiant and the Dire. The Dota2 senate consists of senators from these two parties. The senate wants to decide on a change in the Dota2 game using a round-based voting procedure. In each round, each senator can exercise one of two rights:
-
Ban one senator's right. A senator can make another senator lose all of their rights in this round and all following rounds.
-
Announce the victory. If a senator finds that all senators who still have the right to vote are from the same party, that senator can announce the victory and decide on the change in the game.
You are given a string senate representing each senator's party. The character 'R' represents the Radiant party and 'D' represents the Dire party. If there are n senators, the size of the given string is n.
The round-based procedure goes from the first senator to the last senator in the given order and repeats round after round until the voting ends. Senators who have lost their rights are skipped.
Assuming every senator is smart enough and plays the best strategy for their own party, predict which party will finally announce the victory and change the Dota2 game.
Function Signature
def predict_party_victory(senate: str) -> str:
Rules
-
Within a round, senators act in the order of the string. The next round starts again from index 0, skipping banned senators.
-
Return exactly
"Radiant"
or
"Dire"
.
Constraints
-
n == len(senate)
-
1 <= n <= 10^4
-
senate[i]
is either
'R'
or
'D'
.
Examples
Input: senate = "RD"
Output: "Radiant"
The Radiant senator at index 0 acts first and bans the Dire senator at index 1. In the next round the Dire senator is skipped and the Radiant senator announces victory.
Input: senate = "RDD"
Output: "Dire"
The Radiant senator at index 0 bans the Dire senator at index 1, and the Dire senator at index 2 then bans the Radiant senator. In the next round only a Dire senator remains, so Dire announces victory.
Input: senate = "DDRRR"
Output: "Dire"
The Dire senators at indices 0 and 1 ban the Radiant senators at indices 2 and 3, and the Radiant senator at index 4 bans the Dire senator at index 0. In the second round the Dire senator at index 1 bans the last Radiant senator, so Dire wins even though it started with fewer senators.