package leetcode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * https://leetcode.com/problems/dota2-senate/
 */
public class Problem649 {
    public String predictPartyVictory(String senate) {
        List<Integer> radiants = new ArrayList<>();
        List<Integer> dires = new ArrayList<>();
        char[] chars = senate.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == 'R') {
                radiants.add(i);
            } else {
                dires.add(i);
            }
        }
        int radiantIdx = 0;
        int direIdx = 0;
        Set<Integer> bannedRadiants = new HashSet<>();
        Set<Integer> bannedDires = new HashSet<>();
        while (bannedRadiants.size() <= radiants.size() || bannedDires.size() <= dires.size()) {
            for (int i = 0; i < chars.length; i++) {
                if (bannedRadiants.size() == radiants.size()) {
                    return "Dire";
                }
                if (bannedDires.size() == dires.size()) {
                    return "Radiant";
                }
                if (chars[i] == 'R') {
                    if (bannedRadiants.contains(i)) {
                        continue;
                    }
                    bannedDires.add(dires.get(direIdx++));
                } else {
                    if (bannedDires.contains(i)) {
                        continue;
                    }
                    bannedRadiants.add(radiants.get(radiantIdx++));
                }
            }
        }
        return "";
    }

    public static void main(String[] args) {
        Problem649 prob = new Problem649();
//        System.out.println(prob.predictPartyVictory("RD")); // Radiant
//        System.out.println(prob.predictPartyVictory("RDD")); // Dire
//        System.out.println(prob.predictPartyVictory("RDRD")); // Radiant
//        System.out.println(prob.predictPartyVictory("RDDR")); // Radiant
//        System.out.println(prob.predictPartyVictory("R")); // Radiant
//        System.out.println(prob.predictPartyVictory("D")); // Dire
//        System.out.println(prob.predictPartyVictory("DDRRR")); // Dire
//        System.out.println(prob.predictPartyVictory("RDDRDDDRRRDDRDRDRDDDDRRDR")); // Dire
        System.out.println(prob.predictPartyVictory("DRRDRDRDRDDRDRDR")); // Radiant
    }
}

@@ -16,108 +16,8 @@
 e;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0A
 /**%0A
@@ -160,99 +160,55 @@
     
-List%3CInteger%3E radiants = new ArrayList%3C%3E();%0A        List%3CInteger%3E dires = new ArrayList%3C%3E()
+int radiantCount = 0;%0A        int direCount = 0
 ;%0A  
@@ -357,24 +357,23 @@
  radiant
-s.add(i)
+Count++
 ;%0A      
@@ -411,16 +411,15 @@
 dire
-s.add(i)
+Count++
 ;%0A  
@@ -452,253 +452,48 @@
     
-int radiantIdx = 0;%0A        int direIdx = 0;%0A        Set%3CInteger%3E bannedRadiants = new HashSet%3C%3E();%0A        Set%3CInteger%3E bannedDires = new HashSet%3C%3E();%0A        while (bannedRadiants.size() %3C= radiants.size() %7C%7C bannedDires.size() %3C= dires.size()
+while (direCount %3E 0 %7C%7C radiantCount %3E 0
 ) %7B%0A
@@ -569,48 +569,22 @@
 if (
-bannedRadiants.size() == radiants.size()
+direCount == 0
 ) %7B%0A
@@ -611,20 +611,23 @@
 return %22
-Dire
+Radiant
 %22;%0A     
@@ -663,42 +663,25 @@
 if (
-bannedDires.size() == dires.size()
+radiantCount == 0
 ) %7B%0A
@@ -700,39 +700,36 @@
         return %22
-Radiant
+Dire
 %22;%0A             
@@ -797,154 +797,249 @@
    i
-f (bannedRadiants.contains(i)) %7B%0A                        continue;%0A                    %7D%0A                    bannedDires.add(dires.get(direIdx++))
+nt j = (i + 1) %25 chars.length;%0A                    while (chars%5Bj%5D != 'D') %7B%0A                        j++;%0A                        j = j %25 chars.length;%0A                    %7D%0A                    chars%5Bj%5D = ' ';%0A                    direCount--
 ;%0A  
@@ -1050,32 +1050,53 @@
           %7D else
+ if (chars%5Bi%5D == 'D')
  %7B%0A             
@@ -1107,220 +1107,386 @@
    i
-f (bannedDires.contains(i)) %7B%0A                        continue;%0A                    %7D%0A                    bannedRadiants.add(radiants.get(radiantIdx++));%0A                %7D%0A            %7D%0A        %7D%0A        return %22
+nt j = (i + 1) %25 chars.length;%0A                    while (chars%5Bj%5D != 'R') %7B%0A                        j++;%0A                        j = j %25 chars.length;%0A                    %7D%0A                    chars%5Bj%5D = ' ';%0A                    radiantCount--;%0A                %7D%0A            %7D%0A        %7D%0A        if (direCount == 0) %7B%0A            return %22Radiant%22;%0A        %7D%0A        return %22Dire
 %22;%0A 
@@ -1580,18 +1580,16 @@
 m649();%0A
-//
         
@@ -1643,34 +1643,32 @@
 %22)); // Radiant%0A
-//
         System.o
@@ -1712,34 +1712,32 @@
 RDD%22)); // Dire%0A
-//
         System.o
@@ -1785,34 +1785,32 @@
 %22)); // Radiant%0A
-//
         System.o
@@ -1858,34 +1858,32 @@
 %22)); // Radiant%0A
-//
         System.o
@@ -1936,18 +1936,16 @@
 Radiant%0A
-//
         
@@ -1995,34 +1995,32 @@
 (%22D%22)); // Dire%0A
-//
         System.o
@@ -2074,18 +2074,16 @@
 // Dire%0A
-//
         

Update problem 649