Magical Candy Bags

	public int maxCandies(int[] arr, int K) {
		PriorityQueue<Integer> maxHeap = new PriorityQueue<Integer>(Comparator.reverseOrder());
		for (int i : arr)
		int maxCandies = 0;
		for (int i = 1; i <= K; i++) {
			int rem = maxHeap.remove();
			maxCandies += rem;
			maxHeap.add(rem / 2);

		return maxCandies;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s