Skip to content

1910. Remove All Occurrences of a Substring #1300

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to repeatedly remove all occurrences of a substring part from the string s until no more occurrences exist. Each time we remove the leftmost occurrence of part, we need to check the resulting string again for new occurrences that might have formed due to the removal.

Approach

  1. Iterative Removal: Continuously check for the leftmost occurrence of the substring part in the string s.
  2. String Modification: Each time the substring is found, remove it and form a new string from the remaining parts before and after the removed substring.
  3. Repeat Until Done: Continue this process until no more occurrences of part are found in the string.

This approach ensures that after each removal, we che…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Feb 11, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants