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 herePriorityQueue<Integer>q=newPriorityQueue<>();for(inti:A)q.add(i);intoperations=0;while(q.peek()<k&&q.size()>=2){intsmaller=q.remove();intsmall=q.remove();intmix=smaller+(small*2);q.add(mix);operations++;}return(q.peek()>=k)?operations:-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 →
Simple Java solution using PriorityQueue