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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if string remains palindrome after removing given number of characters
- Maximum increase in value of Matrix to keep maximum rows and columns unchanged
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Program to check diagonal matrix and scalar matrix
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- 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 if a Matrix is Invertible
- Check for possible path in 2D matrix
- Check whether a given matrix is orthogonal or not
- Check if a given matrix is Hankel or not
- Check whether the given Matrix is balanced or not
- Check if a Matrix is Bitonic or not
- Check if Matrix sum is prime or not
- Check if the Matrix follows the given constraints or not
- Check if a given matrix is sparse or not
- Program to check idempotent matrix
- Check if possible to cross the matrix with given power
- Check whether a Matrix is a Latin Square or not
- Program to check if matrix is singular 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 firstname.lastname@example.org. 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.