Check whether Matrix T is a result of one or more 90 ° rotations of Matrix mat | C ++ program for the above approach ; Function to check whether another matrix can be created by rotating mat one or more times by 90 degrees ; If the dimensions of both the arrays don 't match ; Return false ; Map to store all rows , columns and their reversed versions ; Iterate in the range [ 0 , M - 1 ] ; Increment the frequency of the i 'th row by 1 ; Reverse the i 'th row ; Increment the frequency of the i 'th row by 1 ; Iterate in the range [ 0 , N - 1 ] ; Stores the i 'th column ; Iterate in the range [ 0 , M - 1 ] ; Increment the frequency of the i 'th column by 1 ; Reverse the i 'th column ; Increment the frequency of the i 'th column by 1 ; Iterate in the range [ 0 , M - 1 ] ; If frequency of the i 'th row  is more in T[][] than in the  mat[][]. ; Decrement the frequency of the i 'th row by 1 ; Iterate in the range [ 0 , N - 1 ] ; Stores the ith column ; Iterate in the range [ 0 , M - 1 ] ; If frequency of the i 'th column  is more in T[][] than in mat[][]. ; Decrement the frequency of the i 'th  column by 1 ; Return " Yes " ; Driver code ; Input ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; string findRotation ( vector < vector < int > > & mat , vector < vector < int > > & T ) { if ( T . size ( ) != mat . size ( ) || T [ 0 ] . size ( ) != mat [ 0 ] . size ( ) ) { return " No " ; } map < vector < int > , int > m ; for ( int i = 0 ; i < mat . size ( ) ; i ++ ) { m [ mat [ i ] ] += 1 ; reverse ( mat [ i ] . begin ( ) , mat [ i ] . end ( ) ) ; m [ mat [ i ] ] += 1 ; } for ( int i = 0 ; i < mat [ 0 ] . size ( ) ; i ++ ) { vector < int > r = { } ; for ( int j = 0 ; j < mat . size ( ) ; j ++ ) { r . push_back ( mat [ j ] [ i ] ) ; } m [ r ] += 1 ; reverse ( r . begin ( ) , r . end ( ) ) ; m [ r ] += 1 ; } for ( int i = 0 ; i < T . size ( ) ; i ++ ) { if ( m [ T [ i ] ] <= 0 ) { return " No " ; } m [ T [ i ] ] -= 1 ; } for ( int i = 0 ; i < T [ 0 ] . size ( ) ; i ++ ) { vector < int > r = { } ; for ( int j = 0 ; j < T . size ( ) ; j ++ ) { r . push_back ( T [ j ] [ i ] ) ; } if ( m [ r ] <= 0 ) { return " No " ; } m [ r ] -= 1 ; } return " Yes " ; } int main ( ) { vector < vector < int > > mat = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; vector < vector < int > > T = { { 3 , 6 , 9 } , { 2 , 5 , 8 } , { 1 , 4 , 7 } } ; cout << findRotation ( mat , T ) ; return 0 ; }