Print left rotation of array in O ( n ) time and O ( 1 ) space | Python3 implementation to print left rotation of any array K times ; Function For The k Times Left Rotation ; The collections module has deque class which provides the rotate ( ) , which is inbuilt function to allow rotation ; Print the rotated array from start position ; Driver Code ; Function Call
from collections import deque NEW_LINE def leftRotate ( arr , k , n ) : NEW_LINE INDENT arr = deque ( arr ) NEW_LINE arr . rotate ( - k ) NEW_LINE arr = list ( arr ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 3 , 5 , 7 , 9 ] NEW_LINE n = len ( arr ) NEW_LINE k = 2 NEW_LINE leftRotate ( arr , k , n ) NEW_LINE DEDENT