Question: def nestedRemoval(text: str, leftPattern: str, rightPattern: str) -> str You will be given three strings, the first string is a sentence knownas text that contains

def nestedRemoval(text: str, leftPattern: str, rightPattern: str) -> str

You will be given three strings, the first string is a sentence knownas text that contains at least one occurrence of leftPatternand rightPattern. Left pattern and right patternare single characters strings that you are attempting to remove from the string. Your goal is to remove only thepatterns when the left pattern hasan equal number of correspondingright patterns. The patterns are removed in pairs only when there is a balanced number of left and right patterns. The patterns may be nested within the text and there is no guarantee that a left pattern will occur before the right pattern.

Example 1:

text ={ { Muscat } } { } mecum tollgate } poultry quarrymen pantheon asteria

leftPattern ={

rightPattern = }

return =Muscatmecum tollgate } poultry quarrymen pantheon asteria

Example 2:

text =theretofore [ ] [ ] demography ] ] pirouetting morsel [ [ pesticide

leftPattern =[

rightPattern = ]

return =.demography ] ] pirouetting morsel [ [ pesticide

Example 3:

text =( castigate ) alfonso ( ) ) ) emitter sourdough ) taco ( schemata

leftPattern =(

rightPattern = )

return =castigatealfonso) ) emitter sourdough ) Lauren ( schemata

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!