public static int diagonalDifference(List<List<int>> arr)
{
int sumRightToLeft = 0;
int sumLeftToRight = 0;
for(int i = 0; i < arr.Count; i++)
{
if(arr[i].Count == arr[i+1].Count)
{
sumRightToLeft += arr[i][i];
sumLeftToRight += arr[i][arr[i].Count-i-1];
}
else
continue;
}
int abs = Math.Abs(sumRightToLeft - sumRightToLeft);
return abs;
}
When I tried difference to diagonal on matrix I'll take Index out of Range Exception unlike below.
Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I could not understand that didn't happen when I check If block cause which boundaries true. What is my mistake If u find please help me I have not figured out that