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){//sort decreasing by luckCollections.sort(contests,(o1,o2)->o2.get(0).compareTo(o1.get(0)));intlost=0;inttotal=0;for(List<Integer>contest:contests){intluck=contest.get(0);booleanisImportant=contest.get(1)==1;booleanneedWin=k<=lost;if(needWin&&isImportant){total+=(luck*-1);}else{total+=luck;if(isImportant)lost++;}}returntotal;}
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 →
Java code. Passes all test.