Question: def nestedRemoval(text: str, leftPattern: str, rightPattern: str) -> str You will be given three strings, the first string is a sentence known as text that
def nestedRemoval(text: str, leftPattern: str, rightPattern: str) -> str
You will be given three strings, the first string is a sentence known as text that contains at least one occurrence of leftPattern and rightPattern. Left pattern and right pattern are single characters strings that you are attempting to remove from the string. Your goal is to remove only the patterns when left pattern has an equal number of corresponding right 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 = Muscat mecum tollgate } poultry quarrymen pantheon asteria
Example 2:
text = theretofore [ ] [ ] demography ] ] pirouetting morsel [ [ pesticide
leftPattern = [
rightPattern = ]
return = theretofore demography ] ] pirouetting morsel [ [ pesticide
Example 3:
text = ( castigate ) alfonso ( ) ) ) emitter sourdough ) taco ( schemata
leftPattern = (
rightPattern = )
return = castigate alfonso ) ) emitter sourdough ) taco ( schemata
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
