Question bank › Matrix
Dsa Matrix Easy

Matrix Diagonal Sort

Given an m x n matrix, sort each of its diagonals in ascending order. A matrix diagonal is a set of elements that share the same diagonal level, defined by their indices i and j where i - j is constant. Input Format: - The first line contains two integers, m and n. - The next m lines each contain n integers. Output Format: - The sorted matrix returned as m lines of n integers each, with elements sorted on their diagonals. Example: Input: 3 3 3 2 1 1 5 4 2 4 6 Output: 1 2 3 4 5 6 2 4 1

Key concepts

matrixsorting

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.