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.
Do you even require arrays for this question? I did it this way. Please comment if this is more efficient or not. Thank you. My Code:
//My Code
int n, a, i;
int ft,st;
int f=0,s=0,sum=0;
cin>>n;
ft=1;
st=n;
for(i=1;i<=(n*n);i++)
{
cin>>a;
if(i==ft)
{
f += a;
ft += n+1;
}
if(i==st && st!=(n*n))
{
s += a;
st += n-1;
}
}
sum = abs(f-s);
cout<<sum;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
Do you even require arrays for this question? I did it this way. Please comment if this is more efficient or not. Thank you. My Code:
//My Code