#K34022. Diagonal Span of a Matrix
Diagonal Span of a Matrix
Diagonal Span of a Matrix
Given an n x n matrix, your task is to compute the matrix's diagonal groups starting from the top-right corner and moving to the bottom-left corner. Elements that lie on the same diagonal should be grouped together. The order of the groups should follow the order of the diagonals starting from the top-right diagonal.
For example:
Input: 3 1 2 3 4 5 6 7 8 9</p>Output: [[3], [2, 6], [1, 5, 9], [4, 8], [7]]
Please note that the input is read from standard input and the output should be printed to standard output.
inputFormat
The input begins with an integer n (the size of the matrix). The following n lines each contain n space-separated integers representing the rows of the matrix.
Example:
3 1 2 3 4 5 6 7 8 9
outputFormat
Print a list of lists representing the grouped diagonal elements starting from the top-right to the bottom-left. The output should follow the Python list representation format.
Example:
[[3], [2, 6], [1, 5, 9], [4, 8], [7]]## sample
3
1 2 3
4 5 6
7 8 9
[[3], [2, 6], [1, 5, 9], [4, 8], [7]]