Input: mat[][] = [[0, 0, 1],
[1, 1, 1],
[1, 0, 0]];
Output: 2
Value of mat[1][0] is not equal to mat[0][1].
Value of mat[2][1] is not equal to mat[1][2].
So, two flip are required.
Input: mat[][] = [[1, 1, 1, 1, 0],
[0, 1, 0, 1, 1],
[ 1, 0, 0, 0, 1],
[0, 1, 0, 1, 0],
[0, 1, 0, 0, 1]]
Output: 3
The idea is to find minimum flips required to make upper triangle of matrix equals to lower triangle of the matrix. To do so, we run two nested loop, outer loop from i = 0 to n i.e., for each row of the matrix and the inner loop from j = 0 to i, and check whether mat[i][j] is equal to mat[j][i]. Count of number of instances where they are not equal will be the minimum flips required to make matrix symmetric along main diagonal.