Skip to content

Instantly share code, notes, and snippets.

@Nasah-Kuma
Last active October 5, 2022 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nasah-Kuma/812dbf02fa5700b10b81e269aa689358 to your computer and use it in GitHub Desktop.
Save Nasah-Kuma/812dbf02fa5700b10b81e269aa689358 to your computer and use it in GitHub Desktop.
Solution to HackerRank Climbing the Leaderboards Challenge: https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem?isFullScreen=true
/*
* Complete the 'climbingLeaderboard' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1. INTEGER_ARRAY ranked
* 2. INTEGER_ARRAY player
*/
function climbingLeaderboard(ranked, player) {
const uniqueRank = [... new Set(ranked)];
let playerRank = [];
for (let i = 0; i < player.length; i++) {
while (uniqueRank && player[i] >= uniqueRank[uniqueRank.length - 1])
uniqueRank.pop();
playerRank.push(uniqueRank.length + 1);
}
return playerRank;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment