You are viewing a single comment's thread. Return to all comments →
Solution for c#: // the if !added at the end is in case the player is ranked in last position.
public static List climbingLeaderboard(List ranked, List player) { List playerRanks = new List(); int position = 0; int nextIndex = 0; int prev = -1;
for(int i = player.Count-1; i >= 0; i--){ bool added = false; for(int j = nextIndex; j < ranked.Count; j++){ if (player[i] >= ranked[j]) { playerRanks.Add(position + 1); added = true; break; } nextIndex++; if(ranked[j] != prev){ prev = ranked[j]; position++; } } if(!added){ playerRanks.Add(position+1); } } playerRanks.Reverse(); return playerRanks; }
Seems like cookies are disabled on this browser, please enable them to open this website
Climbing the Leaderboard
You are viewing a single comment's thread. Return to all comments →
Solution for c#: // the if !added at the end is in case the player is ranked in last position.
public static List climbingLeaderboard(List ranked, List player) { List playerRanks = new List(); int position = 0; int nextIndex = 0; int prev = -1;