Reversal algorithm for right rotation of an array | Function to reverse arr from index start to end ; Function to right rotate arr of size n by d ; function to pr an array ; Driver code
def reverseArray ( arr , start , end ) : NEW_LINE INDENT while ( start < end ) : NEW_LINE INDENT arr [ start ] , arr [ end ] = arr [ end ] , arr [ start ] NEW_LINE start = start + 1 NEW_LINE end = end - 1 NEW_LINE DEDENT DEDENT def rightRotate ( arr , d , n ) : NEW_LINE INDENT reverseArray ( arr , 0 , n - 1 ) ; NEW_LINE reverseArray ( arr , 0 , d - 1 ) ; NEW_LINE reverseArray ( arr , d , n - 1 ) ; NEW_LINE DEDENT def prArray ( arr , size ) : NEW_LINE INDENT for i in range ( 0 , size ) : NEW_LINE INDENT print ( arr [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE k = 3 NEW_LINE rightRotate ( arr , k , n ) NEW_LINE prArray ( arr , n ) NEW_LINE