Microsoft - Sr Software Engineer - player ranking update

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-08-21Added By Anonymous
Source: Link
Microsoft - Sr Software Engineer - player ranking update This is similar to this post https://leetcode.com/discuss/interview-question/1491917/appropriate-data-structure-to-store-data So, we have between 1 to 250K gamers, each have their own score. Their score can change anytime and we're asked to output player X's rank at any given time. score can range between 0 to 1 million. we can just use player index as player id, so player id will range from 0 to 249,999. Input will consist of (there will be less than 200K lines of input) : 3 -> first line indicates how many players there are, this will be followed by 3 lines of initial score 150 -> player 0's initial score 20 -> player 1's initial score 2100 -> player 2's score, next lines will be commands, starting with either G or U. G for querying player X's current rank, U for updating player X's score, affecting the whole player ranking G 1 -> player 1's rank is dead last with measly score 20, so, output 3 G 0 -> player 0's score is currently 150, rank is 2, so, output is 2 U 1 200 -> player 1's score is now 200, changing his rank to 2 G 1 -> player 1's rank is now 2, output 2 G 0 -> player 0's is now dead last with score 150, output 3 and so on... what would be the efficient way to solve this? I dont think resorting the entire player whenever score is updated would be efficient for this. Any help is appreciated.
Comments