DEV Community

duccanhole
duccanhole

Posted on

3

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
  • 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;
}
Enter fullscreen mode Exit fullscreen mode

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay