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.
coz this is a square matrix, we can calculate the first and second sums at the same time.
funcdiagonalDifference(arr[][]int32)int32{// Write your code heresize:=len(arr[0])-1sum1,sum2:=int32(0),int32(0)fori,j:=0,size;i<=size;i,j=i+1,j-1{sum1+=arr[i][i]sum2+=arr[i][j]}res:=sum1-sum2ifres>0{returnres}return-res}
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 →
GO
coz this is a square matrix, we can calculate the first and second sums at the same time.