Given N*N matrix, rotate it by 90 degree to left and right without extra memory
You ask many questions on CodeReview, which in itself is good, but you have to start helping the reviewers actually review your code. You have this habit of dumping code and expecting a review. It does not work that way (very well). For a start, let's review the ideal process for a 'real' review:


you present neat and working code for review.
you include a description of the context of the code - what it does, why it is needed, and what constraints it has.
you provide some specifications or documentation for any complicated or significant algorithms
the reviewer reviews the code, not only for neatness, and style, but to:

check the code works the way it is supposed to (by visual inspection)
suggest alternative approaches that may achieve the same results faster or in a better way
suggest alternative approaches that may produce different results but may be better for other reasons

signs off that the code is:

good (or great and gives you a high five)
good enough but has some future anticipated improvements
not good enough and needs to be fixed then resubmitted



The details, descriptions, references and specifications you provide with the request is essential if the reviewer is going to give a decent review.

On Code review, the process continues with:


upvoting answers that are helpful (and down-voting those that are not).
accepting answers that (among other answers) best address your concerns.


Your question above is lacking any description of what the code is supposed to do, and how it does it. All you do say is:


I want hints and reviews
it works
what is the complexity


As a result, the only specification available and description of what the code should be doing, is what the code actually does. Or the title of the post....



Bottom line is that you have only given a fraction of what is needed for a good review, so, I will take a stab at doing a review with similar feedback....

A good alternative approach for your code is:

public static void rotateByNinetyToLeft(int[][] m) {

    int e = m.length - 1;
    int c = e / 2;
    int b = e % 2;
    for (int r = c; r &gt;= 0; r--) {
        for (int d = c - r; d &lt; c + r + b; d++) {
            int t   = m[c - r][d];
            m[c - r][d] = m[d][e - c + r];
            m[d][e - c + r] = m[e - c + r][e - d];
            m[e - c + r][e - d] = m[e - d][c - r];
            m[e - d][c - r] = t;
        }
    }
}


This approach is O(n) time complexity (n is the number of pixels in the matrix), and O(1) space complexity

I have tested this and it works.

You can use the right-handed approach for rotateByNinetyToRight