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.
publicstaticintluckBalance(intk,List<List<Integer>>contests){// Categorize importants and count unimportantintluck=0;List<Integer>importantContests=newArrayList<>();for(List<Integer>arr:contests){intluckValue=arr.get(0);intisImportant=arr.get(1);if(isImportant==1){importantContests.add(luckValue);}else{luck+=luckValue;}}// Sort by huge valueimportantContests.sort(Collections.reverseOrder());// Plus or minus for(inti=0;i<importantContests.size();i++){luck+=(i<k)?importantContests.get(i):-importantContests.get(i);}returnluck;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Luck Balance
You are viewing a single comment's thread. Return to all comments →