I'm new to c++ and I was trying to solve a c++ practise problem on hacker rank. After compiling I got the compiler message "Segmentation Fault" when trying to get the absolute difference between the sums of the two diagonals in a square matrix.
I have narrowed down the problem to line 8 but I don't know how to solve it.
int diagonalDifference(vector<vector<int>> arr) {
int sumA,sumB;
int n = arr.size();
for (int i=0;i<n;++i) {
sumA += arr[i][i];
sumB += arr[n-i][n-i];
}
return abs(sumA - sumB);
}
I expect the output to be an absolute difference between the sum of the two diagonals in a square matrix.