What is Dota2 Senate
Senators are R or D in a circle. The next senator who has not been banned bans one senator of the other party. The party that bans every opponent wins.
Approach
Visualization & algorithm
The finished picture is on screen when the page opens. Next and Play start from the first step. The controls sit under the picture and the pseudocode.
Complexity
| Piece | Cost | Why |
|---|---|---|
| Time | O(n) | Each senator is banned at most once and acts at most once more. |
| Space | O(n) | The two queues. |
Implementation
from collections import deque
def solve(self, senate):
r = deque(i for i,c in enumerate(senate) if c=='R')
d = deque(i for i,c in enumerate(senate) if c=='D')
n = len(senate)
while r and d:
if r[0] < d[0]:
r.append(r.popleft()+n); d.popleft()
else:
d.append(d.popleft()+n); r.popleft()
return 'Radiant' if r else 'Dire'