Last active
October 5, 2022 12:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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