Print left rotation of array in O ( n ) time and O ( 1 ) space | Java implementation for print left rotation of any array K times ; Function for the k times left rotation ; In Collection class rotate function takes two parameters - the name of array and the position by which it should be rotated The below function will be rotating the array left in linear time Collections . rotate ( ) rotate the array from right hence n - k ; Print the rotated array from start position ; Driver code ; Function call
import java . io . * ; import java . util . * ; class GFG { static void leftRotate ( Integer arr [ ] , int k , int n ) { Collections . rotate ( Arrays . asList ( arr ) , n - k ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { Integer arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = arr . length ; int k = 2 ; leftRotate ( arr , k , n ) ; } }