Skip to content

Practice Remove All Occurrences of a Substring

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1910
LeetCode Problem

Remove All Occurrences of a Substring

Problem Statement

Repeatedly remove the leftmost occurrence of part from s, joining the remaining text after each removal. Continue until part no longer occurs, including occurrences created by earlier removals. Return the resulting string.

Source: Remove All Occurrences of a Substring on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "daabcbaabcbc", part = "abc"
Output
"dab"

# Example 2

Input
s = "axxxxyyyyb", part = "xy"
Output
"ab"

Constraints

1 <= s.length <= 1000
1 <= part.length <= 1000
s​​​​​​ and part consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Remove All Occurrences of a Substring.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.