package leetcode;

/**
 * https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/
 */
public class Problem1296 {
    public boolean isPossibleDivide(int[] nums, int k) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1296 prob = new Problem1296();
        System.out.println(prob.isPossibleDivide(new int[]{1,2,3,3,4,4,5,6}, 4)); // true
        System.out.println(prob.isPossibleDivide(new int[]{3,2,1,2,3,4,3,4,5,9,10,11}, 3)); // true
        System.out.println(prob.isPossibleDivide(new int[]{3,3,2,2,1,1}, 3)); // true
        System.out.println(prob.isPossibleDivide(new int[]{1,2,3,4}, 3)); // false
    }
}

@@ -12,16 +12,43 @@
 tcode;%0A%0A
+import java.util.TreeMap;%0A%0A
 /**%0A * h
@@ -223,494 +223,763 @@
     
-// TODO%0A        return false;
+TreeMap%3CInteger, Integer%3E map = new TreeMap%3C%3E();%0A        for (int num : nums) %7B
 %0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1296 prob = new Problem1296();%0A        System.out.println(prob.isPossibleDivide(new int%5B%5D%7B1,2,3,3,4,4,5,6%7D, 4)); // true%0A        System.out.println(prob.isPossibleDivide(new int%5B%5D%7B3,2,1,2,3,4,3,4,5,9,10,11%7D, 3)); // true%0A        System.out.println(prob.isPossibleDivide(new int%5B%5D%7B3,3,2,2,1,1%7D, 3)); // true%0A        System.out.println(prob.isPossibleDivide(new int%5B%5D%7B1,2,3,4%7D, 3)); // false
+    if (!map.containsKey(num)) %7B%0A                map.put(num, 1);%0A            %7D else %7B%0A                map.put(num, map.get(num) + 1);%0A            %7D%0A        %7D%0A        while (!map.isEmpty()) %7B%0A            Integer key = map.firstKey();%0A            for (int i = key; i %3C key + k; i++) %7B%0A                if (!map.containsKey(i)) %7B%0A                    return false;%0A                %7D else %7B%0A                    int count = map.get(i) - 1;%0A                    if (count == 0) %7B%0A                        map.remove(i);%0A                    %7D else %7B%0A                        map.put(i, count);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return true;
 %0A   

Solve problem 1296