Skip to content

Dota2 Senate

MediumStack
Decode it first. Clues, constraints, pattern and plan before any code.

A senate has two parties, Radiant (R) and Dire (D). The string senate lists the senators in their speaking order. Voting goes in rounds: in each round, every senator who still has their rights acts once, in order, and may ban one other senator, who loses all rights for the rest of the game (including the rest of this round). Rounds repeat until all senators with rights belong to one party, and that party wins.

Every senator plays optimally for their own party. Return "Radiant" or "Dire", the party that wins.

senate = "RD"   →  "Radiant"   (R bans D first)
senate = "RDD"  →  "Dire"      (R bans the first D, the second D bans R)

Constraints

  • n == senate.length
  • 1 <= n <= 10^4
  • Each senate[i] is R or D.