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.
This is my solution for the problem, however the weird thing is when I run the code in my IntellijIDE with the test cases that are not successful the answer I receive is correct but when the same code runs in Hackerrank's server it gives the wrong output. Weird:
publicstaticList<Integer>climbingLeaderboard(List<Integer>ranked,List<Integer>player){// Write your code hereint[]ranks=newint[ranked.size()];ranks[0]=1;intrank=1;for(inti=1;i<ranked.size();i++){if(!Objects.equals(ranked.get(i-1),ranked.get(i)))rank++;ranks[i]=rank;}System.out.println(Arrays.toString(ranks));List<Integer>answer=newArrayList<>();inti=0,j=ranks.length-1;while(i<player.size()){while(j>=0&&player.get(i)>ranked.get(j))j--;if(j==-1)answer.add(1);else{if(player.get(i)<ranked.get(j))answer.add(ranks[j]+1);elseanswer.add(ranks[j]);}i++;}returnanswer;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Climbing the Leaderboard
You are viewing a single comment's thread. Return to all comments →
This is my solution for the problem, however the weird thing is when I run the code in my IntellijIDE with the test cases that are not successful the answer I receive is correct but when the same code runs in Hackerrank's server it gives the wrong output. Weird: