Rotate a matrix by 90 degree in clockwise direction without using any extra space | javascript implementation of above approach ; Function to rotate the matrix 90 degree clockwise ; printing the matrix on the basis of observations made on indices . ; Driver code
var N = 4 ; function rotate90Clockwise ( arr ) { for ( j = 0 ; j < N ; j ++ ) { for ( i = N - 1 ; i >= 0 ; i -- ) document . write ( arr [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } var arr = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; rotate90Clockwise ( arr ) ;