Dota2 Senate - Problem

In the world of Dota2, there are two parties: the Radiant and the Dire. The Dota2 senate consists of senators coming from two parties.

The Senate wants to decide on a change in the Dota2 game. The voting for this change is a round-based procedure. In each round, each senator can exercise one of the two rights:

  1. Ban one senator's right: A senator can make another senator lose all his rights in this and all the following rounds.
  2. Announce the victory: If this senator found the senators who still have rights to vote are all from the same party, he can announce the victory and decide on the change in the game.

Given a string senate representing each senator's party belonging. The character 'R' and 'D' represent the Radiant party and the Dire party.

The round-based procedure starts from the first senator to the last senator in the given order. This procedure will last until the end of voting. All the senators who have lost their rights will be skipped during the procedure.

Suppose every senator is smart enough and will play the best strategy for his own party. Predict which party will finally announce the victory and change the Dota2 game. The output should be "Radiant" or "Dire".

Input & Output

Example 1 — Basic Case
$ Input: senate = "RD"
Output: Radiant
💡 Note: R senator (position 0) acts first and bans D senator (position 1). Only R remains, so Radiant wins.
Example 2 — Multiple Rounds
$ Input: senate = "RDD"
Output: Dire
💡 Note: Round 1: R(0) bans D(1), D(2) survives. Round 2: Only D remains, so Dire wins.
Example 3 — Complex Pattern
$ Input: senate = "DDRRR"
Output: Radiant
💡 Note: Multiple rounds of competition, but R senators eventually outnumber and eliminate all D senators.

Constraints

  • 1 ≤ senate.length ≤ 104
  • senate[i] is either 'R' or 'D'

Visualization

Tap to expand
Dota2 Senate: Strategic Voting ProcessInput Senate:RDDRProcess:• Each senator can ban one opponent• Senators act in order, skip banned ones• Smart strategy: ban next opponent in line• Continue until only one party remainsOutput:Winner Party🎯 Key Insight: Optimal strategy leads to predictable winner!
Understanding the Visualization
1
Input
String of senators: 'R' for Radiant, 'D' for Dire
2
Process
Senators take turns banning opponents in optimal order
3
Output
Winning party name: 'Radiant' or 'Dire'
Key Takeaway
🎯 Key Insight: Each senator optimally bans the next opponent to maximize their party's chances
Asked in
Amazon 15 Microsoft 10
32.0K Views
Medium Frequency
~15 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen