Question: def Game ( Str , N ) : # Calculate the initial displacement initial _ displacement = Str . count ( ' S ' )
def GameStr N: # Calculate the initial displacement initialdisplacement StrcountS StrcountR # Count the number of R in the string countR StrcountR # Maximum changes possible is either all R or exactly N changes changespossible mincountR N # Calculate the maximum possible displacement after changes maxdisplacement initialdisplacement changespossible # If not all N changes were used for R return the max possible with necessary N if countR N: # If less R than N next best displacement might be less by unused N maxdisplacement maxdisplacement N countR return maxdisplacement # Example usage with input: Str SSSRSSS N printGameStr N # Expected Output:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
