using modulo to go to the firs column after the last column
ans [ i ] [ j ] = arr [ j ] [ ( i + j ) % n ] ; } } return ans ; } function show ( arr , n ) { let res = solve ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { document . write ( res [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } }