Repeatedly remove every occurrence of a given substring from a string until no occurrence remains.
Given a string s and a string part, repeatedly find and remove an occurrence of part from s until part no longer appears in the string.
Return the final string after all such removals.
The removals may happen in any order of occurrence, but the end result must reflect continuing removals until the substring disappears completely.
Input Format
- Two strings are given:
sandpart. partis the substring to remove froms.- Treat the input as plain lowercase/ASCII strings unless otherwise specified by the platform.
Output Format
- Return a single string: the result after removing all occurrences of
partrepeatedly.
Constraints
1 <= s.length1 <= part.length <= s.length- The exact official platform limits are not provided here.
- A correct solution should be efficient enough for linear or near-linear processing of the string.
Example 1
Input
s = "daabcbaabcbc", part = "abc"
Output
"dab"
Explanation
Remove "abc" from "daabcbaabcbc" -> "dabaabcbc". Remove "abc" again -> "dabcbc". Remove "abc" again -> "dab".
Example 2
Input
s = "axxxxyyyyb", part = "xy"
Output
"ab"
Explanation
After repeatedly removing "xy" occurrences, only "ab" remains.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.