package leetcode;

/**
 * https://leetcode.com/problems/zuma-game/
 */
public class Problem488 {
    public int findMinStep(String board, String hand) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem488 prob = new Problem488();
        System.out.println(prob.findMinStep("WRRBBW", "RB")); // -1
        System.out.println(prob.findMinStep("WWRRBBWW", "WRBRW")); // 2
        System.out.println(prob.findMinStep("G", "GGGGG")); // 2
        System.out.println(prob.findMinStep("RBYYBBRRB", "YRBGB")); // 3
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -207,32 +207,1554 @@
     
-// TODO%0A        return 0
+Map%3CCharacter, Integer%3E handMap = new HashMap%3C%3E();%0A        for (char c : hand.toCharArray()) %7B%0A            if (!handMap.containsKey(c)) %7B%0A                handMap.put(c, 1);%0A            %7D else %7B%0A                handMap.put(c, handMap.get(c) + 1);%0A            %7D%0A        %7D%0A        return findMinStep(board, handMap, 0);%0A    %7D%0A%0A    private static int findMinStep(String board, Map%3CCharacter, Integer%3E hand, int idx) %7B%0A        if (idx %3E= board.length()) %7B%0A            return Integer.MAX_VALUE;%0A        %7D%0A        int i = idx;%0A        int j = i + 1;%0A        while (i %3C board.length() && j %3C board.length() && board.charAt(i) == board.charAt(j)) %7B%0A            j++;%0A        %7D%0A        int min = Integer.MAX_VALUE;%0A        if (j - i %3E= 2) %7B%0A            if (j - i == 2) %7B%0A                if (hand.containsKey(board.charAt(i))) %7B%0A                    int count = hand.get(board.charAt(i)) - 1;%0A                    if (count == 0) %7B%0A                        hand.remove(board.charAt(i));%0A                    %7D else %7B%0A                        hand.put(board.charAt(i), count);%0A                    %7D%0A                %7D%0A            %7D%0A            String left = board.substring(0, idx);%0A            String right = board.substring(j);%0A            int val = findMinStep(left + right, hand, 0);%0A            if (val == Integer.MIN_VALUE) %7B%0A                val = 0;%0A            %7D%0A            if (j - 1 == 2) %7B%0A                val =+ 1;%0A            %7D%0A            min = Math.min(min, val);%0A        %7D%0A        min = Math.min(min, findMinStep(board, hand, j));%0A        return min
 ;%0A  
@@ -1843,24 +1843,26 @@
 oblem488();%0A
+//
         Syst
@@ -1917,16 +1917,90 @@
 ; // -1%0A
+//        System.out.println(prob.findMinStep(%22WWRRBBWW%22, %22WRBRW%22)); // 2%0A
         
@@ -2055,32 +2055,34 @@
 %22WRBRW%22)); // 2%0A
+//
         System.o
@@ -2122,32 +2122,34 @@
 %22GGGGG%22)); // 2%0A
+//
         System.o

Update problem 488