Sum the diagonal elements in an array
Asked in the Technical stage.
Given a square 2D integer array matrix, return the sum of its main diagonal, consisting of elements where the row and column indices are equal.
Function signature: def sum_diagonal(matrix):
Input: a non-empty square list of lists of integers. Output: one integer containing the main diagonal sum.
Example: matrix = [[1, 2], [3, 4]] returns 5. Example: matrix = [[5]] returns 5.
Constraints: 1 <= n <= 1000, len(matrix) == n, every row has length n, and each value is between -10^9 and 10^9.
def sum_diagonal(matrix):