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

Why complexity of nested loop? This is how I solved it:

long sum1 = 0; long sum2 = 0;

for (int i = 0; i < n ; i++) { sum1 += a[i][i]; sum2 += a[i][n - 1 - i]; } Console.WriteLine(Math.Abs(sum1 - sum2));

This is what I did too! Takes O(n) time. Cheers!

Did the same in Java [ O(n) time complexity ]:

for(int i=0; i<n; i++){ sum1+=arr[i][i]; sum2+=arr[i][n-1-i]; } System.out.println(Math.abs(sum1-sum2));

why did keep + symbols infroont of sum1 and sum2..?

its like SUM=SUM+arr[i][i];

The + indicated that ^

Amazing Man!! The solution is just AMAZING !!

## Diagonal Difference

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

Why complexity of nested loop? This is how I solved it:

long sum1 = 0; long sum2 = 0;

This is what I did too! Takes O(n) time. Cheers!

Did the same in Java [ O(n) time complexity ]:

why did keep + symbols infroont of sum1 and sum2..?

its like SUM=SUM+arr[i][i];

The + indicated that ^

Amazing Man!! The solution is just AMAZING !!