Jesse and Cookies

  • + 0 comments

    short java8

    public static int cookies(int k, List<Integer> A) {
            PriorityQueue<Integer> minHeap = new PriorityQueue<>(A);
            while( minHeap.size() > 1 &&  minHeap.peek() < k)
                minHeap.add(minHeap.poll() + minHeap.poll()*2); 
            return minHeap.peek() >= k? A.size() - minHeap.size() : -1;
        }