code every day with me

–DAY 21–

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let’s solve problem today:

Problem: Climbing the Leaderboard
Detail: here


This content originally appeared on DEV Community and was authored by duccanhole

--DAY 21--

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:

  • Problem: Climbing the Leaderboard
  • Detail: here
  • Idea:
    • Remove the duplicate number of ranked
    • Because player array was sorted, we will find the rank from bottom to top by traversing from tail to head of array
  • My solution(javascript):
function climbingLeaderboard(ranked, player) {
    ranked = [... new Set(ranked)];
    let ans=[],i=ranked.length-1;
    for(let score of player){
        while(i>=0){
            if(score<ranked[i]){
                ans.push(i+2);
                break;
            }
            i--;
        }
        if(i<0) ans.push(1);
    }
    return ans;
}

-->If you have better solution or any question, please comment below. I will appreciate.


This content originally appeared on DEV Community and was authored by duccanhole


Print Share Comment Cite Upload Translate Updates
APA

duccanhole | Sciencx (2021-11-16T08:24:15+00:00) code every day with me. Retrieved from https://www.scien.cx/2021/11/16/code-every-day-with-me-8/

MLA
" » code every day with me." duccanhole | Sciencx - Tuesday November 16, 2021, https://www.scien.cx/2021/11/16/code-every-day-with-me-8/
HARVARD
duccanhole | Sciencx Tuesday November 16, 2021 » code every day with me., viewed ,<https://www.scien.cx/2021/11/16/code-every-day-with-me-8/>
VANCOUVER
duccanhole | Sciencx - » code every day with me. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/16/code-every-day-with-me-8/
CHICAGO
" » code every day with me." duccanhole | Sciencx - Accessed . https://www.scien.cx/2021/11/16/code-every-day-with-me-8/
IEEE
" » code every day with me." duccanhole | Sciencx [Online]. Available: https://www.scien.cx/2021/11/16/code-every-day-with-me-8/. [Accessed: ]
rf:citation
» code every day with me | duccanhole | Sciencx | https://www.scien.cx/2021/11/16/code-every-day-with-me-8/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.