4019. Remove K-Balanced Substrings
My accepted Python solution to LeetCode problem 4019, Remove K-Balanced Substrings, running in 8955ms.
- Difficulty: Medium
- Python
- Runtime 8955ms
- Memory 18.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 8955ms, memory 18.2MB, accepted 2025-12-31.
class Solution:
def removeSubstring(self, s: str, k: int) -> str:
target = "(" * k + ")" * k
while target in s:
s = s.replace(target, "", 1)
return s