Imagine you're a teacher managing exam results for your class. You have m students who took n different exams, and you want to rank them based on their performance in one specific exam.
You're given a score matrix where each row represents a student and score[i][j] is the score that student i got on exam j. All scores are unique integers.
Given an integer k, you need to sort the students (rearrange the rows) based on their scores in the k-th exam from highest to lowest.
Goal: Return the matrix with rows sorted by the k-th column in descending order.
Input & Output
Visualization
Time & Space Complexity
Built-in sorting algorithms are typically O(m log m) where m is number of students
Space complexity depends on sorting algorithm used (QuickSort is O(log m), MergeSort is O(m))
Constraints
-
m == score.length -
n == score[i].length -
1 โค m, n โค 250 -
1 โค score[i][j] โค 105 -
scoreconsists of distinct integers -
0 โค k < n