Reverse all elements of given circular array starting from index K | Function to print the 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
function printArray ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } function reverseCircularArray ( arr , N , K ) { let start = K , end = K - 1 ; let count = Math . floor ( N / 2 ) ; while ( count -- ) { let temp = arr [ start % N ] ; arr [ start % N ] = arr [ end % N ] ; arr [ end % N ] = temp ; start ++ ; end -- ; if ( end === - 1 ) { end = N - 1 ; } } printArray ( arr , N ) ; } let arr = [ 3 , 5 , 2 , 4 , 1 ] ; let K = 2 ; let N = arr . length ; reverseCircularArray ( arr , N , K ) ;