You are viewing a single comment's thread. Return to all comments →

Came to the same result, but ruby way. Just one loop

diag1=diag2=0 for i in (0...n) diag1 += a[i][i] diag2 += a[i][n-i-1] end puts (diag1-diag2).abs

Crazy! I got the EXACT same. Important to note you have to pass n to the function.

n

def diagonalDifference(a,n) # Complete this function x = y = 0 for i in (0...n) x += a[i][i] y += a[i][n-1-i] end puts (x-y).abs end

## Diagonal Difference

You are viewing a single comment's thread. Return to all comments →

Came to the same result, but ruby way. Just one loop

Crazy! I got the EXACT same. Important to note you have to pass

`n`

to the function.