For this Question: Given a 2d matrix of size M*N, print the zig traversal of the matrix as shown:-

Consider a matrix of size 5*4
 1 2 3 4
 5 6 7 8
 9 10 11 12
 13 14 15 16
 17 18 19 20

ZigZag traversal:-

 1
 5 2
 9 6 3
 13 10 7 4
 17 14 11 8
 18 15 12
 19 16
 20First line of input contains two integers M and N. Next M lines contains N space- separated integers each.

Constraints:-
1 <= M, N <= 100
1 <= Matrix[i][j] <= 100000Print the zig- zag traversal of the matrix as shown.Sample Input:-
4 3
1 2 3
4 5 6
7 8 9
10 11 12

Sample Output:-
1
4 2
7 5 3
10 8 6
11 9
12, I have written this Solution Code: M, N = [int(x) for x in input().split()]
mat = []
for i in range(M):
    single_row = list(map(int, input().split()))
    mat.append(single_row)

def diagonalOrder(arr, n, m):
    ans = [[] for i in range(n + m - 1)]
     
    for i in range(m):
        for j in range(n):
            ans[i + j].append(arr[j][i])
     
    for i in range(len(ans)):
        for j in range(len(ans[i])):
            print(ans[i][j], end = " ")
        print()

diagonalOrder(mat, M, N), In this Programming Language: Python, Now tell me if this Code is compilable or not?