Image rotation for interviews

code for the problem

It is easy to implement image rotation.For a given nxn matrix You are needed to perform 2 steps:

1.Take transpose along the diagonal.
This you can do by: if(i!=j) then swap(arr[i][j],arr[j][i])

  1. Reverse all rows.
    This you can do by: swap(arr[i][j],arr[i][n-1-j])
    Try to code by yourself using these conditions and you will get it clear.

Note that this is when you want rotation in clockwise direction by 90 degree.
If you want the rotation in anti clockwise direction, you will have to take transpose along the other diagonal.
Just do some index manipulation and swap the elements.