Check whether Matrix T is a result of one or more 90 ° rotations of Matrix mat | 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 " ; Input ; Function call
function findRotation ( mat , T ) { if ( T . length != mat . length T [ 0 ] . length != mat [ 0 ] . length ) { return " " ; } let m = new Map ( ) ; for ( let i = 0 ; i < mat . length ; i ++ ) { if ( m . has ( mat [ i ] ) ) { m . set ( mat [ i ] , m . get ( mat [ i ] ) + 1 ) } else { m . set ( mat [ i ] , 1 ) } mat [ i ] . reverse ( ) ; if ( m . has ( mat [ i ] ) ) { m . set ( mat [ i ] , m . get ( mat [ i ] ) + 1 ) } else { m . set ( mat [ i ] , 1 ) } } for ( let i = 0 ; i < mat [ 0 ] . length ; i ++ ) { let r = [ ] ; for ( let j = 0 ; j < mat . length ; j ++ ) { r . push ( mat [ j ] [ i ] ) ; } if ( m . has ( r ) ) { m . set ( r , m . get ( r ) + 1 ) } else { m . set ( r , 1 ) } r . reverse ( ) ; if ( m . has ( r ) ) { m . set ( r , m . get ( r ) + 1 ) } else { m . set ( r , 1 ) } } for ( let i = 0 ; i < T . length ; i ++ ) { if ( m . get ( T [ i ] ) <= 0 ) { return " " ; } m . set ( T [ i ] , m . get ( T [ i ] ) - 1 ) ; } for ( let i = 0 ; i < T [ 0 ] . length ; i ++ ) { let r = [ ] ; for ( let j = 0 ; j < T . length ; j ++ ) { r . push ( T [ j ] [ i ] ) ; } if ( m . get ( r ) <= 0 ) { return " " ; } m . set ( r , m . get ( r ) - 1 ) ; } return " " ; } let mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; let T = [ [ 3 , 6 , 9 ] , [ 2 , 5 , 8 ] , [ 1 , 4 , 7 ] ] ; document . write ( findRotation ( mat , T ) ) ;