Luck Balance Hackerrank

Question Link  Click Here

C++ SOLUTION: 

int luckBalance(int k, vector<vector<int>> contests) {
int i, j;
sort(contests.begin(), contests.end(), greater<>());
int max = 0 ;

for (i = 0; i < contests.size(); i++) {
if(k == 0 && contests[i][j + 1] == 1 ){
max = max - contests[i][j];
} else if (contests[i][j + 1] == 1) {
k = k - 1;
max = max + contests[i][j];

}

if (contests[i][j + 1] == 0){
max = max = max + contests[i][j];
}
}

return max ;

} 

Comments

Popular posts from this blog

Infosys - Monster RPG GAME Sample Question Solution

Hackerrank -- C++ - Variable Sized Array Solution