Geeks For Geeks Cyclically Rotate An Array By One

 class Compute {

    

    public void rotate(long arr[], long n)

    {

       int end=(int)n-1;

for(end=(int)n-1;end>0;end--){

long temp=0L;//to initialize an element of long to 0(0L in long) 

temp=arr[end];

arr[end]=arr[end-1];

arr[end-1]=temp;

}

            //if you want to print result here then use below two lines also

/*for(int i=0;i<(int)n;i++){

System.out.print(arr[i]+" ");

}*/

    }

}


Time: O(n)

Space: O(1)

Concept: Arithmetic Shift Left 


//Please comment and like. 

//Thanks 😀.



Comments

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks