![]() |
VOOZH | about |
Given a binary matrix Mat[][] of size N*N, the task is to find the minimum number of flips to be performed such that the matrix is identical for all rotations.
Examples:
Input: Mat[][] = {{1, 0, 0}, {0, 1, 0}, {1, 0, 1}}
Output: 1
Explanation: Change the element at row = 1, col = 3 from 0 to 1.
Now for all the rotations the matrix is identical.Input: {{0}}
Output: 0
Approach: To solve the problem follow the below idea:
Rotate the matrix 4 times and for every position check how many of elements needs to be changed based on their positions in each rotation.
Follow the steps mentioned below to implement the observation:
Below is the implementation of the above approach:
1
Time Complexity: O(N2)
Auxiliary Space: O(N2)