human
Maximize absolute displacement from origin by moving on X | Recursive function to find the maximum absolute displacement from origin by performing the given set of moves.
If i is equal to N.
If S [ i ] is equal to 'L.
If S [ i ] is equal to 'R.
If S [ i ] is equal to '?.
Function to find the maximum absolute displacement from the origin.
Return the maximum absolute displacement.
Input.
Function call"
Solution in Python:
assistant
#Here is code to maximize absolute displacement from origin by moving on X and the other steps required.
 def DistRecursion ( S , i , dist ) :
	if i == len ( S ) :
		return abs ( dist )
'
	if S [ i ] == ' L ' :
		return DistRecursion ( S , i + 1 , dist - 1 )
'
	if S [ i ] == ' R ' :
		return DistRecursion ( S , i + 1 , dist + 1 )
'
	return max ( DistRecursion ( S , i + 1 , dist - 1 ) , DistRecursion ( S , i + 1 , dist + 1 ) )
def maxDistance ( S ) :
	return DistRecursion ( S , 0 , 0 )
S = " ? RRR ? "
print ( maxDistance ( S ) )