![]() |
VOOZH | about |
Given a string 'S' and a substring 'sub', the task is to determine whether 'S' can be reduced to an empty string by repeatedly deleting one occurrence at a time of the substring 'sub' whenever it appears in the string.
Example:
Input:
s = "aaaaaa"
sub = "aa"Output:
True (string becomes empty)Explanation:
"aaaaaa" → remove "aa" → "aaaa"
"aaaa" → remove "aa" → "aa"
"aa" → remove "aa" → ""
This method keeps checking if the substring exists in the main string, and whenever it does, we remove it using slicing. The loop continues until no more removals are possible, and then we check if the string is empty.
False
Explanation:
Recursive deletion using slicing means removing a substring from a string again and again by cutting it out using slicing (s[: ]). The process keeps calling itself until either the string becomes empty or no more deletions are possible.
False
Explanation:
This method removes the substring using replace() inside a recursive function. Each recursive call removes the substring again and again until either the string becomes empty or no more removals are possible.
False
Explanation:
An iterative replace() loop repeatedly calls replace() inside a loop to update a string step-by-step until all desired changes are applied.
False
Explanation: