Tap here to switch tabs
Problem
Submissions

Problem: Sort Matrix by Diagonals

med
30 min
Try to solve the Sort Matrix by Diagonals problem.

Statement

You are given an n×nn \times n integer matrix grid. Return the matrix obtained after sorting each of its diagonals according to the following rules:

  • Diagonals in the bottom left triangle, including the main diagonal, must be sorted in non increasing order.

  • Diagonals in the top right triangle, excluding the main diagonal, must be sorted in non decreasing order.

Constraints:

  • grid.length ==== grid[i].length ==n== n

  • 1≤n≤101 \leq n \leq 10

  • −105≤-10^5 \leq grid[i][j] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sort Matrix by Diagonals

med
30 min
Try to solve the Sort Matrix by Diagonals problem.

Statement

You are given an n×nn \times n integer matrix grid. Return the matrix obtained after sorting each of its diagonals according to the following rules:

  • Diagonals in the bottom left triangle, including the main diagonal, must be sorted in non increasing order.

  • Diagonals in the top right triangle, excluding the main diagonal, must be sorted in non decreasing order.

Constraints:

  • grid.length ==== grid[i].length ==n== n

  • 1≤n≤101 \leq n \leq 10

  • −105≤-10^5 \leq grid[i][j] ≤105\leq 10^5