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
|
2380 Discussions
|
Please Login in order to post a comment
Remove duplicates in ranked array and then sort the player array in descending order. iterate through ranked array until find the point which is less than the player's, and append the (index + 1) into the result array. Finally sort the result in descending order.
Remove duplicates from rank array, use binary search to find closest number to the new alice score. time complexity O(n + mlogn) :)
For anyone trying to figure out the timeouts with TypeScript, I had to change all of my loops (including maps, reduces, and forEaches) to traditional for-loops. I believe the traditional for loop is more effiecient than the built in functions, so that is what got mine to work, particularly for test case number 6.
You can assume that the list of scores from the player will always be in ascending order. It would be nice to know that as part of the criteria.
As an alternative, you could probably turn the player scores into pairs with their array index, sort them ascending, and then map the ranks to the pair's index to ensure correct ordering even if scores are out of order. That would be a real world-ish scenario.