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
Prijavi se da vidiš povijest predaja
PrijavaPrijavi se da koristiš AI mentora
PrijavaTests12
Visible tests
Skriveni test 7
Skriveni test 8
Skriveni test 9
Skriveni test 10
Skriveni test 11
Skriveni test 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid