#Given an array reverse it without using extra-space #Time-complexity: O(n), Auxiliary-space: O(1) # Iterative def reverse_array(a) right=a.length-1 left=0 while(left [5,4,3,2,1] # Recursive #driver program def driver_program(a) right=a.length-1 left=0 reverse_array(a,left,right) print a end def reverse_array(a,left,right) return if left>=right #swap the elements temp=a[left] a[left]=a[right] a[right]=temp reverse_array(a,left+1,right-1) end driver_program([1,2,3,4,5]) # => [5,4,3,2,1]