We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Diagonal Difference
- Discussions
Diagonal Difference
Diagonal Difference
Sort by
recency
|
681 Discussions
|
Please Login in order to post a comment
C#
function diagonalDifference(arr: number[][]): number { const {a, b} = arr.reduce((acc, item, idx, arr) => { acc.a += item[idx] acc.b += item[arr.length - idx - 1] return acc }, {a: 0, b: 0})
return Math.abs(a - b) }
GO
coz this is a square matrix, we can calculate the first and second sums at the same time.