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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Climbing the Leaderboard
  5. Discussions

Climbing the Leaderboard

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 2147 Discussions, By:

recency

Please Login in order to post a comment

  • ivanli656
    3 hours ago+ 0 comments
    def climbingLeaderboard(ranked, player):
        # Write your code here
        rank=[1]
        r=1
        for i in range(1,len(ranked)):
            if ranked[i]!=ranked[i-1]:
                r+=1
            rank.append(r)
        rank.append(r+1)
        ret=[]
        j=len(ranked)-1
        for p in player:
            while j>=0 and p>=ranked[j]:
                j-=1
            ret.append(rank[j+1])
        return ret
    

    Use an additional array to record the rank of each interval.

    0|
    Permalink
  • lctrgzmn
    4 hours ago+ 0 comments

    Here is a Rust version that passes all test cases.

    fn climbingLeaderboard(mut ranked: Vec<i32>, mut player: Vec<i32>) -> Vec<i32> {
        ranked.dedup();
        let mut ranked = ranked.into_iter().peekable();
        let mut positions = vec![];
        let mut pos = 1;
        while let Some(score) = player.pop() {
            loop {
                match ranked.peek() {
                    Some(&ranking) => {
                        if score >= ranking {
                            positions.push(pos);
                            break;
                        } else {
                            pos += 1;
                            ranked.next();
                        }
                    }
                    None => {
                        positions.push(pos);
                        break;
                    }
                };
            }
        }
        positions.reverse();
        positions
    }
    
    0|
    Permalink
  • ahusseini1981
    2 days ago+ 0 comments

    here is my java code: it failed on large numbers anyone can comment. //score : rank list to return //rank : used to calculated player rank //ps : is the player score //rs : is the rank score

        List<Integer> score = new ArrayList<Integer>();
        int rank,rs, ps;
        for(int i=0;i<player.size();i++){
            ps = player.get(i);
            rank=1; 
            for(int j=0;j<ranked.size();j++){
                rs = ranked.get(j);
                if(ps >= rs)
                    break;
                else if(j<ranked.size()-1 && rs == ranked.get(j+1))
                        continue;
                else rank++;
            }
            score.add(rank);    
        }              
        return score;
    
    0|
    Permalink
  • bskavitha21
    4 days ago+ 0 comments
    int j=0;int rank=1;
     for (int i=player.size()-1;i>=0;i--)
     {
         while(true)
         {
             cout<<player[i]<<" "<<ranked[j]<<endl;
             cout<<j<<" "<<rank<<endl;
             if(player[i]>=ranked[j])
                {player[i]=rank;break;}
             else if (j+1==ranked.size())
                {player[i]=rank+1;break;}
             cout<<j<<" "<<rank<<endl;
             if(ranked[j]>ranked[j+1])
                rank++;
            cout<<j<<" "<<rank<<endl;
             j++;
         }
     }
    return player;
    
    0|
    Permalink
  • 21CS019_KPRIET
    6 days ago+ 0 comments

    def climbingLeaderboard(ranked, player): ranked = list(sorted(set(ranked),reverse = True)) result = []

    for score in player:
        while ranked and score >= ranked[-1]:
            ranked.pop()
        result.append(len(ranked)+1)
        return result
    
    -1|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy