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.

All you need is to have an understanding of mathematics and observe the mathematical expression. For example in the diagonal diffrence in a 3X3 array we have the following values for i,j respectively:

0,0 0,1 0,2

1,0 1,1 1,2

2,0 2,2 2,2

so the primary diagonal is 0,0 1,1 2,2 so it is obvious i=j
the secondary diagonal is 2,0 1,1 0,2 so we can easily observe that i+j=n-1 (2+0=3-1, 1+1=2, 0+2=2)

## Diagonal Difference

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

How did you came up with the equation? I mean I'm new to programming and I need tips.

All you need is to have an understanding of mathematics and observe the mathematical expression. For example in the diagonal diffrence in a 3X3 array we have the following values for i,j respectively:

0,0 0,1 0,2

1,0 1,1 1,2

2,0 2,2 2,2

so the primary diagonal is 0,0 1,1 2,2 so it is obvious i=j the secondary diagonal is 2,0 1,1 0,2 so we can easily observe that i+j=n-1 (2+0=3-1, 1+1=2, 0+2=2)

nothing explained is obvious or as clear as could be.

I agree entirely. This was not a clear solution but clean code. Very confusing to a new coder.

nice solution