Sort the Students by Their Kth Score

There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the i^th student got in the j^th exam. The matrix score contains distinct integers only.

You are also given an integer k. Sort the students, i.e. the rows of the matrix, by their scores in the k^th (0-indexed) exam from highest to lowest.

Return the matrix after sorting it.

Example 1
Inputscore = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2
Output[[7,5,11,2],[10,6,9,1],[4,8,3,15]]
The students' scores in exam 2 are 11, 9, and 3, so the rows are ordered by those scores from highest to lowest.
Example 2
Inputscore = [[3,4],[5,6]], k = 0
Output[[5,6],[3,4]]
The students' scores in exam 0 are 5 and 3, so the row with score 5 comes first.

Constraints

  • m == score.length
  • n == score[i].length
  • 1 <= m, n <= 250
  • 1 <= score[i][j] <= 10^5
  • score consists of distinct integers.
  • 0 <= k < n

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate