We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticintcookies(intk,List<Integer>A){// Write your code hereintitration=0;PriorityQueue<Integer>Q=newPriorityQueue<>();for(inti:A){Q.add(i);}while(Q.size()>1&&Q.peek()<k){intleast=Q.poll();intsecondLeast=Q.poll();// Even if secondLeast >= k, we can still do:// Combine: newSweet = least + 2 * secondLeastintnewSweetness=least+2*secondLeast;Q.add(newSweetness);itration++;}if(Q.peek()!=null&&Q.peek()>=k){returnitration;}else{return-1;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →
java