Skip to content

2545. Sort the Students by Their Kth Score 👍

  • Time: $O(mn\log m)$
  • Space: $O(mn)$
1
2
3
4
5
6
7
8
9
class Solution {
 public:
  vector<vector<int>> sortTheStudents(vector<vector<int>>& score, int k) {
    ranges::sort(score, [k](const vector<int>& a, const vector<int>& b) {
      return a[k] > b[k];
    });
    return score;
  }
};
1
2
3
4
5
6
class Solution {
  public int[][] sortTheStudents(int[][] score, int k) {
    Arrays.sort(score, (a, b) -> Integer.compare(b[k], a[k]));
    return score;
  }
}
1
2
3
class Solution:
  def sortTheStudents(self, score: list[list[int]], k: int) -> list[list[int]]:
    return sorted(score, key=lambda x: -x[k])