2545. Sort the Students by Their Kth Score Medium
1/**
2 * [2545] Sort the Students by Their Kth Score
3 *
4 * 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.
5 * 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 the highest to the lowest.
6 * Return the matrix after sorting it.
7 *
8 * <strong class="example">Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2022/11/30/example1.png" style="width: 600px; height: 136px;" />
10 * Input: score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2
11 * Output: [[7,5,11,2],[10,6,9,1],[4,8,3,15]]
12 * Explanation: In the above diagram, S denotes the student, while E denotes the exam.
13 * - The student with index 1 scored 11 in exam 2, which is the highest score, so they got first place.
14 * - The student with index 0 scored 9 in exam 2, which is the second highest score, so they got second place.
15 * - The student with index 2 scored 3 in exam 2, which is the lowest score, so they got third place.
16 *
17 * <strong class="example">Example 2:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2022/11/30/example2.png" style="width: 486px; height: 121px;" />
19 * Input: score = [[3,4],[5,6]], k = 0
20 * Output: [[5,6],[3,4]]
21 * Explanation: In the above diagram, S denotes the student, while E denotes the exam.
22 * - The student with index 1 scored 5 in exam 0, which is the highest score, so they got first place.
23 * - The student with index 0 scored 3 in exam 0, which is the lowest score, so they got second place.
24 *
25 *
26 * Constraints:
27 *
28 * m == score.length
29 * n == score[i].length
30 * 1 <= m, n <= 250
31 * 1 <= score[i][j] <= 10^5
32 * score consists of distinct integers.
33 * 0 <= k < n
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/sort-the-students-by-their-kth-score/
39// discuss: https://leetcode.com/problems/sort-the-students-by-their-kth-score/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn sort_the_students(score: Vec<Vec<i32>>, k: i32) -> Vec<Vec<i32>> {
45 vec![]
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2545() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.