Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Remove K-Balanced Substrings

XPChallenge Points: 10
levelLevel: Easy

You are given a string s consisting only of '(' and ')', and an integer k.
A string is considered k-balanced if it contains exactly k consecutive '(' followed by k consecutive ')',
i.e., '(' * k + ')' * k.
For example:
• If k = 2, a k-balanced substring is "(())".
• If k = 3, a k-balanced substring is "((()))".
Your task is to repeatedly remove all non-overlapping k-balanced substrings from s, joining the remaining parts each time.
Continue this process until no more k-balanced substrings exist.
Finally, return the resulting string after all possible removals.

Example 1:

Input: s = "(()())" k = 1

Output: "()"

Example 2:

Input: s = "((()))" k = 3""

Output: ""

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result