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.
Binary search would do and turns out it was pretty straight forward. Here is my snippet in Javascript.
functionbinarySearch(arr,val){letstart=0;letend=arr.length-1;while(start<=end){constmid=Math.floor((start+end)/2);if(arr[mid]===val){returnmid+1;// Found the exact value}elseif(val>arr[mid]){end=mid-1;// Search in the left half}else{start=mid+1;// Search in the right half}}// Determine the rank based on the insertion positionreturnstart+1;}functionclimbingLeaderboard(ranked,player){// Write your code hereconstuniqRanked=[...newSet(ranked)];returnplayer.map((score)=>{returnbinarySearch(uniqRanked,score);});}
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 →
Binary search would do and turns out it was pretty straight forward. Here is my snippet in Javascript.