#2545
Medium Algorithms Sort the students by their kth score
Array Sorting Matrix
86.0% acceptance
Feb 25, 2026
731
53
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 ith student got in the jth 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 kth (0-indexed) exam from the highest to the lowest.
Return the matrix after sorting it.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn sort_the_students(mut score: Vec<Vec<i32>>, k: i32) -> Vec<Vec<i32>> {
let k = k as usize;
score.sort_unstable_by(|a, b| b[k].cmp(&a[k]));
score
}
}