here we use stack for reversing the elements of diagonal
s = [ ] NEW_LINE i = j NEW_LINE k = column NEW_LINE while ( i < n and k >= 0 ) : NEW_LINE INDENT s . append ( mat [ i ] [ k ] ) NEW_LINE i += 1 NEW_LINE k -= 1 NEW_LINE DEDENT