Skip to content
Decoder

Dota2 Senate

Medium

Problem

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.

Example 1

Input
senate = "RD"
Output
"Radiant"
Why
R bans D first

Example 2

Input
senate = "RDD"
Output
"Dire"
Why
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.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.