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.
Add any non-important contests L to a running total
Add any import contests L to a list
Sort and reverse the list
Loop through the list
a. Add the L to total for x = 0 to k
b. After that, subtract the rest of the L values in the list
// Complete the luckBalance function below.staticintluckBalance(intk,int[][]contests){inttotal=0;List<int>impWins=newList<int>();for(intx=0;x<contests.GetLength(0);x++){if(contests[x][1]==1)impWins.Add(contests[x][0]);elsetotal+=contests[x][0];}impWins.Sort();impWins.Reverse();for(intx=0;x<impWins.Count;x++){if(x<k)total+=impWins[x];elsetotal-=impWins[x];}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 →
C# passed all tests: