Given a NxN matrix. The task is to check if after reversing all of the rows of the given Matrix, the matrix remains same or not.
Input : N = 3 1 2 1 2 2 2 3 4 3 Output : Yes If all the rows are reversed then matrix will become: 1 2 1 2 2 2 3 4 3 which is same. Input : N = 3 1 2 2 2 2 2 3 4 3 Output : No
- A most important observation is for the matrix to be same after row reversals, each single row must be palindromic.
- Now to check if a row is palindromic, maintain two pointers, one pointing to start and other to end of row. Start comparing the values present and do start++ and end–. Repeat the process until all elements are checked till the middle of the row. If at each step elements are same, then row is palindromic otherwise not.
- If any of the Row is not palindromic then answer is No.
Below is the implementation of the above approach:
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Program to check diagonal matrix and scalar matrix
- Program to check if a matrix is Binary matrix or not
- Check if it is possible to make the given matrix increasing matrix or not
- Check for possible path in 2D matrix
- Check if a given matrix is Hankel or not
- Check if a Matrix is Invertible
- Check whether a given matrix is orthogonal or not
- Check if a given matrix is sparse or not
- Check if possible to cross the matrix with given power
- Program to check idempotent matrix
- Program to check if a matrix is symmetric
- Program to check if matrix is singular or not
- Check if sums of i-th row and i-th column are same in matrix
- Check given matrix is magic square or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.