java.lang.Object
g2501_2600.s2545_sort_the_students_by_their_kth_score.Solution

public class Solution extends Object
2545 - Sort the Students by Their Kth Score.<p>Medium</p> <p>There is a class with <code>m</code> students and <code>n</code> exams. You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>score</code>, where each row represents one student and <code>score[i][j]</code> denotes the score the <code>i<sup>th</sup></code> student got in the <code>j<sup>th</sup></code> exam. The matrix <code>score</code> contains <strong>distinct</strong> integers only.</p> <p>You are also given an integer <code>k</code>. Sort the students (i.e., the rows of the matrix) by their scores in the <code>k<sup>th</sup></code> ( <strong>0-indexed</strong> ) exam from the highest to the lowest.</p> <p>Return <em>the matrix after sorting it.</em></p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/11/30/example1.png" alt="" /></p> <p><strong>Input:</strong> score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2</p> <p><strong>Output:</strong> [[7,5,11,2],[10,6,9,1],[4,8,3,15]]</p> <p><strong>Explanation:</strong> In the above diagram, S denotes the student, while E denotes the exam.</p> <ul> <li> <p>The student with index 1 scored 11 in exam 2, which is the highest score, so they got first place.</p> </li> <li> <p>The student with index 0 scored 9 in exam 2, which is the second highest score, so they got second place.</p> </li> <li> <p>The student with index 2 scored 3 in exam 2, which is the lowest score, so they got third place.</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/11/30/example2.png" alt="" /></p> <p><strong>Input:</strong> score = [[3,4],[5,6]], k = 0</p> <p><strong>Output:</strong> [[5,6],[3,4]]</p> <p><strong>Explanation:</strong> In the above diagram, S denotes the student, while E denotes the exam.</p> <ul> <li> <p>The student with index 1 scored 5 in exam 0, which is the highest score, so they got first place.</p> </li> <li> <p>The student with index 0 scored 3 in exam 0, which is the lowest score, so they got second place.</p> </li> </ul> <p><strong>Constraints:</strong></p> <ul> <li><code>m == score.length</code></li> <li><code>n == score[i].length</code></li> <li><code>1 <= m, n <= 250</code></li> <li><code>1 <= score[i][j] <= 10<sup>5</sup></code></li> <li><code>score</code> consists of <strong>distinct</strong> integers.</li> <li><code>0 <= k < n</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • sortTheStudents

      public int[][] sortTheStudents(int[][] score, int k)