Print left rotation of array in O ( n ) time and O ( 1 ) space | JAVA implementation of left rotation of an array K number of times ; Function to leftRotate array multiple times ; To get the starting point of rotated array ; Prints the rotated array from start position ; Driver code ; Function Call ; Function Call ; Function Call
import java . util . * ; import java . lang . * ; import java . io . * ; class arr_rot { static void leftRotate ( int arr [ ] , int n , int k ) { int mod = k % n ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( arr [ ( i + mod ) % n ] + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = arr . length ; int k = 2 ; leftRotate ( arr , n , k ) ; k = 3 ; leftRotate ( arr , n , k ) ; k = 4 ; leftRotate ( arr , n , k ) ; } }