• + 0 comments
    • The idea is to create a set of ranked with distinct values
    • Now we start from the backward of the leadership board to find the position for the player score, that by reducing the index
    • Once we find the score position then insert index + 2 to the resulted array

    function climbingLeaderboard(ranked, player) { // Write your code here const leaderboard = Array.from(new Set(ranked)) const result = [] let index = leaderboard.length - 1 // Start from the lowest rank

    for (let score of player) {
      // Move up the leaderboard until you find the position for the player's score
      while (index >= 0 && score >= leaderboard[index]) {
        index--
      }
      // The player's rank is index + 2 (since index + 1 would be 0-based)
      result.push(index + 2)
    }
    
    return result;
    

    } `