Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5594
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3412
Sort a 2D vector diagonally
Medium Accuracy: 65.18% Submissions: 427 Points: 4

Gived a NxM 2D matrix, rearrange such that
Each diagonal in the lower left triangle of the rectangular grid is sorted in ascending order.
Each diagonal in the upper right triangle of the rectangular grid is sorted in descending order.
The major diagonal in the grid starting from the top-left corner is not rearranged.

Example 1:

Input:
N = 4, M = 5
matrix = {{3 6 3 8 2},
{4 1 9 5 9},
{5 7 2 4 8},
{8 3 1 7 6}}
Output:
3 9 8 9 2
1 1 6 5 8
3 4 2 6 3
8 5 7 7 4
Explanation:
Before:

After:


You don't need to read input or print anything. Your task is to complete the function diagonalSort() which takes the matrix, n and m as input parameter and rearranges the elements of the matrix.

Expected Time Complexity: O(NxM)
Expected Auxiliary Space: O(N+M)

Constraints:
1 <= N,M <= 200
1 <= matrix[i] <= 103