Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 516 Bytes

main_diagonal_product.md

File metadata and controls

22 lines (16 loc) · 516 Bytes
  • Given a list of rows of a square matrix, find the product of the main diagonal.

Exapmples

  [[1, 0], [0, 1]] should return 1
  [[1, 2, 3], [4, 5, 6], [7, 8, 9]] should return 45 

Solution :

def main_diagonal_product(mat):
    product = 1
    for i in range(len(mat)):
        product *= mat[i][i]
    return product

print(main_diagonal_product([[1,0],[0,1]])) # 1