Dota2 Senate

The senate of the Dota2 world has senators from two parties, Radiant (`R`) and Dire (`D`). Voting runs in rounds, in seat order. On their turn, a senator who still has rights may either ban one other senator, who then loses every right in this and all later rounds, or announce victory if every senator still holding rights belongs to their own party. Every senator plays the best strategy for their party. Given the string `senate`, return `"Radiant"` or `"Dire"`, the party that announces victory.

30:00

Dota2 Senate
medium
Free written solution
Topics
Companies

The senate of the Dota2 world has senators from two parties, Radiant (R) and Dire (D). Voting runs in rounds, in seat order. On their turn, a senator who still has rights may either ban one other senator, who then loses every right in this and all later rounds, or announce victory if every senator still holding rights belongs to their own party. Every senator plays the best strategy for their party. Given the string senate, return "Radiant" or "Dire", the party that announces victory.

Example 1:
Input: {"senate":"RD"}
Output: Radiant
Constraints:
  • n=senate.lengthn = \text{senate.length}

  • 1≤n≤1041 \leq n \leq 10^4

  • senate[i]\text{senate}[i] is either ′R′'R' or ′D′'D'.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"senate":"RD"}

senate (seat order = speaking order)

R 1 vs D 1 · 0 banned

R

0

D

1

There are 2 senators. Each one, on their turn, should ban the next opposing senator who would act soonest.

Variables
VariableValue
n2
radiant0
dire0
DepthFunction Call
Stack empty
0/4