• + 0 comments

    hello everyone

    this is my java sol and this it is passing all the tese cases. can anyone give me the suggetion to improve my code public static void printMatrix(List> matrix){ for(int i=0;i> matrix, int r) { // Write your code here int row = matrix.size(); int col = matrix.get(0).size();

    for(int k=0;k<Math.min(row, col)/2;k++){
    int totalElement = (2*(row-2*k) + 2*(col-2*k))-4;
    // System.out.println("total "+totalElement);
    int it=r%totalElement;
    int i=0+k, j=0+k;
    
    while(it>0){
    
        int[] tempb = new int[row];
        tempb[i] = matrix.get(i).get(j);
        while(i<row-1-k){
            tempb[i+1] = matrix.get(i+1).get(j);
            matrix.get(i+1).set(j, tempb[i]);
            i++; 
        }
    
        int[] tempr = new int[col];
        tempr[0] = tempb[i];
        int index=0;
        while(j<col-1-k){
            tempr[index+1] = matrix.get(i).get(j+1);
            matrix.get(i).set(j+1, tempr[index]);
            j++;
            index++;
        }
    
        int[] tempup = new int[row];
        tempup[0] = tempr[index];
        index=0;
        while(i>=1+k){
            tempup[index+1] = matrix.get(i-1).get(j);
            matrix.get(i-1).set(j, tempup[index]);
            i--;
            index++;
        }
    
        int[] templ = new int[col];
        templ[0] = tempup[index];
        index=0;
        while(j>=1+k){
            templ[index+1] = matrix.get(i).get(j-1);
            matrix.get(i).set(j-1, templ[index]);
            j--;
            index++;
        }
        it--;
    }    
        }
    
    printMatrix(matrix);
    }
    

    }