Advertisement
jayati

Dota2 Senate

May 6th, 2024
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     string predictPartyVictory(string senate) {
  4.         queue<int>dq, rq;
  5.         int n = senate.size();
  6.         for(int i =0 ;i < n;i++)
  7.         {
  8.             if(senate[i] == 'R'){
  9.                 rq.push(i);
  10.             }
  11.             else{
  12.                 dq.push(i);
  13.             }
  14.         }
  15.         while(!dq.empty() && !rq.empty())
  16.         {
  17.             int ri = rq.front();
  18.             rq.pop();
  19.             int di = dq.front();
  20.             dq.pop();
  21.             if(ri < di)
  22.             {
  23.                 rq.push(ri+n);
  24.             }
  25.             else{
  26.                 dq.push(di+n);
  27.             }
  28.         }
  29.         if(dq.empty())
  30.         return "Radiant";
  31.         else
  32.         return "Dire";
  33.     }
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement