You are viewing a single comment's thread. Return to all comments →
Here is a Java 8 solution. Because the test requires better time performance I opted for a binary search. Hope it helps.
public static List<Integer> climbingLeaderboard(List<Integer> ranked, List<Integer> player) { List<Integer> scores= new ArrayList<>(player.size()); ranked= ranked.stream().distinct().sorted().collect(toList()); for (Integer p : player) { int index = Collections.binarySearch(ranked, p); if(index<0){ index+=ranked.size()+2; } else{ index= ranked.size()+1 + (-1)*(index+1); } scores.add(index); } return scores; }
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 →
Here is a Java 8 solution. Because the test requires better time performance I opted for a binary search. Hope it helps.