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.
My Java 8 solution, based on a simple Binary Search approach, passing all test cases, for Max Score of 35. Code is fairly self-explanatory.
staticlongminTime(long[]machines,longgoal){Arrays.sort(machines);longfastestMachineNumDays=machines[0];// Binary search boundslonglowNumDays=1;longhighNumDays=fastestMachineNumDays*goal;longresult=highNumDays;while(lowNumDays<=highNumDays){longmidNumDays=lowNumDays+(highNumDays-lowNumDays)/2;// Compute production in 'midNumDays' dayslongtotal=0;for(longm:machines){total+=midNumDays/m;if(total>=goal){break;// early exit if goal reached}}if(total<goal){lowNumDays=midNumDays+1;}else{result=midNumDays;highNumDays=midNumDays-1;}}returnresult;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Time Required
You are viewing a single comment's thread. Return to all comments →
My Java 8 solution, based on a simple Binary Search approach, passing all test cases, for Max Score of 35. Code is fairly self-explanatory.