Dota2 Senate - Problem
In the world of Dota2, there are two competing parties: the Radiant and the Dire. The Dota2 senate consists of senators from both parties who must decide on a game change through a strategic voting process.
The voting follows a round-based procedure where senators take turns in order. Each senator can:
- Ban a senator: Remove another senator's voting rights permanently
- Announce victory: If all remaining senators are from their party
Given a string senate where 'R' represents Radiant and 'D' represents Dire, determine which party will win. All senators play optimally for their party.
Example: senate = "RD" โ "Radiant" (R bans D, then announces victory)
Input & Output
example_1.py โ Basic Case
$
Input:
senate = "RD"
โบ
Output:
"Radiant"
๐ก Note:
Senator R (position 0) acts first and bans senator D (position 1). Now only Radiant senators remain, so Radiant wins.
example_2.py โ Multiple Rounds
$
Input:
senate = "RDD"
โบ
Output:
"Dire"
๐ก Note:
Round 1: R bans first D, second D bans R. Round 2: Only the remaining D can act, so Dire wins.
example_3.py โ Complex Strategy
$
Input:
senate = "DRDRDR"
โบ
Output:
"Dire"
๐ก Note:
Each D bans the next R in sequence. Since D acts first each time, Dire systematically eliminates all Radiant senators.
Visualization
Tap to expand
Understanding the Visualization
1
Setup Queues
Separate senators by party and track their original positions
2
Strategic Banning
Each senator bans their nearest opponent to maximize party advantage
3
Queue Rotation
Winning senators go to back of line for next round
4
Victory Condition
Game ends when only one party has senators remaining
Key Takeaway
๐ฏ Key Insight: Each senator should ban the next opponent in line to maximize their party's chances. Using queues makes this strategy efficient with O(n) complexity.
Time & Space Complexity
Time Complexity
O(n)
Each senator is processed exactly once
โ Linear Growth
Space Complexity
O(n)
Two queues to store senator indices
โก Linearithmic Space
Constraints
- 1 โค senate.length โค 104
- senate[i] is either 'R' or 'D'
- At least one senator from each party must be present initially
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code