Skip to main content
Back to problems
#649
Medium Algorithms

Dota2 senate

String Greedy Queue
49.6% acceptance
Feb 20, 2026
2764
2079
Predict which party (Radiant or Dire) will announce victory in the Dota2 senate voting simulation.

Solution

Rust
Time O(n)
Space O(n)
LeetCode
solution.rs
use std::collections::VecDeque;
impl Solution {
  pub fn predict_party_victory(senate: String) -> String {
    let mut r: VecDeque<i32> = VecDeque::new();
    let mut d: VecDeque<i32> = VecDeque::new();
    let n = senate.len() as i32;
    for (i, c) in senate.chars().enumerate() {
      if c == 'R' { r.push_back(i as i32); }
      else { d.push_back(i as i32); }
    }
    while !r.is_empty() && !d.is_empty() {
      let ri = r.pop_front().unwrap();
      let di = d.pop_front().unwrap();
      if ri < di { r.push_back(ri + n); }
      else { d.push_back(di + n); }
    }
    if r.is_empty() { "Dire".to_string() } else { "Radiant".to_string() }
  }
}