The idea is to calculate sum of diagonals example [[1,2,3],[4,5,6],[7,8,9] the correct answer would be [1,5,9][3,5,7] = total 30
def sum_of_matrix(data):
arr_solver = []
counter = 0
counter2 = -1
while counter < len(data):
arr_solver.append(data[counter][counter])
arr_solver.append(data[counter][counter2])
counter += data[counter][counter2]
counter2 -= data[counter][counter]
return sum(arr_solver)
This is my todays interview question I had, is this a good solution to a question? My idea was to implement a graph and calculate path, but that'd take waaaaay too long and probably wouldn't be able to implement it on the go.
sum_of_matrix([[1,2,3],[4,5,6],[7,8,9]])
aborts withIndexError
. \$\endgroup\$