Player Leaderboard Sorting

Easy
0/40
profile
Contributed by
0 upvote
Asked in company
Signify Innovation Labs

Problem statement

You are developing a leaderboard system for a game. You are given a list of N players, where each player is represented by their name and their score.


Your task is to sort this list of players and print the resulting leaderboard according to two rules:

- Players should be sorted in descending order of their scores (highest score first).

- If two or more players have the same score, they should be sorted by their names in ascending lexicographical (alphabetical) order.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line of input contains an integer N, the number of players.

The next N lines each contain a player's name (a string) and their score (an integer), separated by a space.


Output Format:
The output should consist of N lines, each containing a player's name and score from the sorted list, separated by a space.


Note:
Player names will consist of only lowercase English letters and will not contain spaces.
Sample Input 1:
4
david 100
alice 150
eve 150
bob 100


Sample Output 1:
alice 150
eve 150
bob 100
david 100


Explanation for Sample 1:
The highest score is 150, shared by alice and eve.

We sort these two by name alphabetically: alice comes before eve.

The next highest score is 100, shared by david and bob.

We sort these two by name alphabetically: bob comes before david.

Combining these gives the final sorted order.


Expected Time Complexity:
The expected time complexity is O(N * log N), which is standard for comparison-based sorting.


Constraints:
1 <= N <= 10^5
Player names are strings of length 1 to 20, containing only lowercase letters.
0 <= score <= 1000

Time limit: 1 sec
Approaches (1)
Custom Comparison Sort
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Player Leaderboard Sorting
Full screen
Console