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.
Climbing the Leaderboard
Climbing the Leaderboard
Sort by
recency
|
2309 Discussions
|
Please Login in order to post a comment
public static List climbingLeaderboard(List ranked, List player) { // Write your code here Map map = new HashMap<>(); Map map2 = new HashMap<>(); int i=0; for(int rank: ranked){ if(map.get(rank) == null){ map.put(rank,++i); map2.put(i, rank); } } //System.err.println(map); //System.err.println("---"); //System.err.println(map2); //System.err.println("---"); //System.err.println("i:"+i); List result = new ArrayList<>(); for(int play : player){ if(map.get(play) == null){// {1=100, 2=90, 3=80, 4=70, 5=10} // System.err.println("before while loop i::"+i); // System.err.println(map2); while(i>0 && map2.get(i) !=null && map2.get(i)
O(logN) - Java solution Tip: Use Binary Search since the data is sorted. public static List climbingLeaderboard(List ranked, List player) { // Write your code here List ranks = new ArrayList<>(); ranks.add(1); for (int i = 1 ; i < ranked.size() ; i++) { if (ranked.get(i) < ranked.get(i-1)) { ranks.add(ranks.get(i-1) + 1); } else { ranks.add(ranks.get(i-1)); } } List playerRanks = new ArrayList<>();
int[] arr = new int[1];
} return; } }
}
O(N) solution in C.
Solution in TypeScript. Complexity O(r), where r is the length of ranked array with O(p) space complexity.
python , simple and straightforward
def climbingLeaderboard(ranked, player): # Write your code here ranked = sorted(set(ranked), reverse=True)