Input: ‘N’ = 3, ‘STUDENTS’ = [[‘naruto’, 50], [‘sasuke’, 95], [‘sakura’, 65]]
Output: [[‘sasuke’, 95], [‘sakura’, 65], [‘naruto’, 50]]
In the example above you can see that ‘sasuke’ got the highest marks so he came first in the output followed by ‘sakura’ and ‘naruto’ with the lowest marks.
The first line will contain the integer 'T', denoting the number of test cases.
For each test case, the first line will contain a single integer 'N', the number of students in the class.
The next ‘N’ line contains two elements first is a string representing the name of the student and the second is an integer denoting the marks of the student.
For each test case print the elements in the defined order above.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^5
1 <= L <= 20
0 <= M <= 100
The Sum of the value of N for all the test cases is <= 10^5.
Time Limit: 1 sec
Here ‘L’ is the size of the string representing the name of the student and ‘M’ is the marks of the student.
We can sort the array in nondecreasing order on the basis of marks and if the two marks are equal then we can put the element with the lexicographically smaller name first. We can use the sort function with a custom comparator. You can learn more about them for python here and for c++you can directly google it.