You are viewing a single comment's thread. Return to all comments →
static int luckBalance(int k, int[][] c) { PriorityQueue<Integer> imp = new PriorityQueue<>(Collections.reverseOrder()); int luck = 0; for(int row = 0; row < c.length; row++){ if(c[row][1] == 0) luck += c[row][0]; else imp.offer(c[row][0]); } boolean decreaseLuck = false; while(!imp.isEmpty()){ if(k == 0) decreaseLuck = true; if(decreaseLuck == true) luck -= imp.poll(); else luck += imp.poll(); k--; }return luck; }
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 Solution
PASSES 100% OF TEST CASES ✅
O(N) TIME COMPLEXITY ✅
SHORTEST CODE YOU CAN FIND IN JAVA! 🔥