human
Reverse the substrings of the given String according to the given Array of indices | Function to reverse a string.
Swap character starting from two corners.
Function to reverse the string with the given array of indices.
Reverse the from 0 to A [ 0 ].
Reverse the for A [ i ] to A [ i + 1 ].
Reverse String for A [ n - 1 ] to length.
Driver Code"
Solution in Python:
assistant
#Here is code to reverse the substrings of the given String according to the given Array of indices and the other steps required.
 def reverseStr ( str , l , h ) :
	n = h - l
	for i in range ( n // 2 ) :
		str [ i + l ] , str [ n - i - 1 + l ] = str [ n - i - 1 + l ] , str [ i + l ]
def reverseString ( s , A , n ) :
	reverseStr ( s , 0 , A [ 0 ] )
	for i in range ( 1 , n ) :
		reverseStr ( s , A [ i - 1 ] , A [ i ] )
	reverseStr ( s , A [ n - 1 ] , len ( s ) )
s = " abcdefgh "
s = [ i for i in s ]
A = [ 2 , 4 , 6 ]
n = len ( A )
reverseString ( s , A , n )
print ( " " . join ( s ) )