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.
function climbingLeaderboard(ranked, player) {
const uniqueRanked = Array.from(new Set(ranked));
const result = [];
let i = uniqueRanked.length - 1;
player.forEach((score) => {
while (i >= 0 && score >= uniqueRanked[i]) {
i--;
}
// Add 1 because ranks are 1-based, and array indices are 0-based.
// and 1 for the next rank
result.push((i + 1) + 1);
});
return result;
}
Cookie support is required to access HackerRank
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 →
JS
}