Compare Matrix Diagonals
A square matrix is like a table with two important diagonals: one running left to right, and the other running right to left. The function diagonal_difference receives a matrix arr as a list of lists of numbers. Add the primary diagonal, add the secondary diagonal, and return the absolute difference between those two sums.
Примеры
Ввод
[[11, 2, 4], [4, 5, 6], [10, 8, -12]]Вывод
15Ввод
[[1, 2], [3, 4]]Вывод
0Ввод
[[5]]Вывод
0Нужно реализовать
def diagonal_difference(arr: list[list[int]]) -> int:
Теги
arraymath
Entre para ver seu histórico de envios
EntrarEntre para usar o AI Mentor
EntrarVisible tests
1
Input
[[11,2,4],[4,5,6],[10,8,-12]]Expected
152
Input
[[1,2],[3,4]]Expected
03
Input
[[5]]Expected
04
Input
[[1,0,1],[0,5,0],[1,0,1]]Expected
05
Input
[[1,2,3],[4,5,6],[9,8,9]]Expected
26
Input
[]Expected
0Focus radio
Paused · SomaFM · Fluid