Number of statements can increase the execution time even your problem is O(n^2)+O(n^2) == O(n^2)


#1

So I tried with first solution which was taking O(n^2)+O(n^2) == O(2n^2). ==> O(n^2). And then I did some changes with code which made it to O(n^2) and then I passed all the test cases and with previous solution I was facing TLE.
My new solution now is

public void rotate(ArrayList<ArrayList<Integer>> a) {
        for(int i = 0; i < a.size(); i++){
            for(int j = i+1; j < a.size(); j++){
                // Swap a[i][j] with a[j][i]
                // Take the transpose
                int temp = a.get(i).get(j);
                a.get(i).set(j, a.get(j).get(i));
                a.get(j).set(i, temp);
            }
// For this row swap values
            for (int j = 0; j < a.size() / 2; j++) {
                int temp = a.get(i).get(j);
                a.get(i).set(j, a.get(i).get(a.size()-j-1));
                a.get(i).set(a.size()-j-1, temp);
            }
        }
    }