Given a N x M matrix which represents the number of rows and number of columns respectively. Each cell of a matrix is occupied by exactly one student. The task is to determine whether we can shuffle each student in such a way that each student should occupy a cell that is adjacent to that student’s original cell, i.e. immediately to the left, right, top or bottom of that cell and after shuffling each cell should occupy by exactly one student.
Input: N = 3, M = 3
Output: Shuffling not possible
Input: N = 4, M = 4
Output: Shuffing is possible
One possible way to shuffle the student is as shown below:
Approach: Check if the number of rows or the number of columns is even then shuffling is possible otherwise no shuffling is possible.
Below is the implementation of the above approach:
Shuffling is possible
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if a given string can be formed using characters of adjacent cells of a Matrix
- Maximum product of 4 adjacent elements in matrix
- 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
- Minimum difference between adjacent elements of array which contain elements from each row of a matrix
- Count of cells in a matrix whose adjacent cells's sum is prime Number
- Check if a grid can become row-wise and column-wise sorted after adjacent swaps
- Count of cells in a matrix which give a Fibonacci number when the count of adjacent cells is added
- Check if all the elements can be made of same parity by inverting adjacent elements
- Check if a Matrix is Invertible
- Check if a given matrix is Hankel or not
- Check if a given matrix is sparse 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.