Reverse all elements of given circular array starting from index K | Function to print array arr [ ] ; Print the array ; Function to reverse elements of given circular array starting from index k ; Initialize two variables as start = k and end = k - 1 ; Initialize count = N / 2 ; Loop while count > 0 ; Swap the elements at index ( start % N ) and ( end % N ) ; Update the start and end ; If end equals to - 1 set end = N - 1 ; Print the circular array ; Driver Code ; Function Call
def printArray ( arr , N ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def reverseCircularArray ( arr , N , K ) : NEW_LINE INDENT start , end = K , K - 1 NEW_LINE count = N // 2 NEW_LINE while ( count ) : NEW_LINE INDENT temp = arr [ start % N ] NEW_LINE arr [ start % N ] = arr [ end % N ] NEW_LINE arr [ end % N ] = temp NEW_LINE start += 1 NEW_LINE end -= 1 NEW_LINE if ( end == - 1 ) : NEW_LINE INDENT end = N - 1 NEW_LINE DEDENT count -= 1 NEW_LINE DEDENT printArray ( arr , N ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 5 , 2 , 4 , 1 ] NEW_LINE K = 2 NEW_LINE N = len ( arr ) NEW_LINE reverseCircularArray ( arr , N , K ) NEW_LINE DEDENT