Dota2 Senate

MediumGreedygreedy

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A senate has senators from two parties, Radiant ('R') and Dire ('D'), seated in the order given by the string senate. Voting proceeds in rounds; within a round, senators act in seat order, and a senator who has been banned is skipped for the rest of the game. On their turn, a senator may **ban** one other senator who is still active, or, if every remaining active senator belongs to their own party, **declare victory** for that party. Every senator plays optimally for their party. Return "Radiant" or "Dire": the party that ends up declaring victory.

Examples

Input: senate = "RD"
Output: "Radiant"
The `R` bans the `D` on the first turn; in the next round only Radiant is left.
Input: senate = "RDD"
Output: "Dire"
`R` bans the first `D`, the second `D` bans `R`, and Dire wins.

Constraints

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

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More greedy problems