package leetcode;

/**
 * https://leetcode.com/problems/rabbits-in-forest/
 */
public class Problem781 {
    public int numRabbits(int[] answers) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem781 prob = new Problem781();
        System.out.println(prob.numRabbits(new int[]{1, 1, 2})); // 5
        System.out.println(prob.numRabbits(new int[]{10, 10, 10})); // 11
        System.out.println(prob.numRabbits(new int[]{})); // 0
        System.out.println(prob.numRabbits(new int[]{1, 0, 1, 0, 0})); // 5
        System.out.println(prob.numRabbits(new int[]{1, 2, 3})); // 9
        System.out.println(prob.numRabbits(new int[]{1, 2, 2, 3})); // 9
        System.out.println(prob.numRabbits(new int[]{1, 2, 2, 2, 3})); // 9
        System.out.println(prob.numRabbits(new int[]{1, 2, 2, 2, 2, 3})); // 12
        System.out.println(prob.numRabbits(new int[]{1, 2, 2, 2, 2, 2, 3})); // 12
        System.out.println(prob.numRabbits(new int[]{1, 2, 2, 2, 2, 2, 2, 3})); // 12
        System.out.println(prob.numRabbits(new int[]{1, 2, 2, 2, 2, 2, 2, 2, 3})); // 15
        System.out.println(prob.numRabbits(new int[]{0})); // 1
        System.out.println(prob.numRabbits(new int[]{0, 0})); // 2
        System.out.println(prob.numRabbits(new int[]{0, 0, 0})); // 3
        System.out.println(prob.numRabbits(new int[]{0, 0, 0, 0})); // 4
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -202,1033 +202,563 @@
     
-// TODO%0A        return 0
+Map%3CInteger, Integer%3E map = new HashMap%3C%3E()
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem781 prob = new Problem781();%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 1, 2%7D)); // 5%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B10, 10, 10%7D)); // 11%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B%7D)); // 0%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 0, 1, 0, 0%7D)); // 5%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 2, 3%7D)); // 9%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 2, 2, 3%7D)); // 9%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 2, 2, 2, 3%7D)); // 9%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 2, 2, 2, 2, 3%7D)); // 12%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 2, 2, 2, 2, 2, 3%7D)); // 12%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 2, 2, 2, 2, 2, 2, 3%7D)); // 12%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B1, 2, 2, 2, 2, 2, 2, 2, 3%7D)); // 15%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B0%7D)); //
+for (int answer : answers) %7B%0A            if (!map.containsKey(answer)) %7B%0A                map.put(answer, 1);%0A            %7D else %7B%0A                map.put(answer, map.get(answer) + 1);%0A            %7D%0A        %7D%0A        int result = 0;%0A        for (Map.Entry%3CInteger, Integer%3E e : map.entrySet()) %7B%0A            result += e.getKey() + 1;%0A            int count = e.getValue() - e.getKey() - 1;%0A            while (count %3E 0) %7B%0A                result += e.getKey() + 1;%0A                count -= e.getKey() +
  1
+;
 %0A   
@@ -766,209 +766,46 @@
     
-System.out.println(prob.numRabbits(new int%5B%5D%7B0, 0%7D)); // 2%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B0, 0, 0%7D)); // 3%0A        System.out.println(prob.numRabbits(new int%5B%5D%7B0, 0, 0, 0%7D)); // 4
+    %7D%0A        %7D%0A        return result;
 %0A   

Solve problem 781