Is Convertible Data
Learn this problemProblem statement
Given a dataset of strings containing only parentheses, characters '(' and ')', the data represented by the string is valid if it is a balanced bracket sequence. One adjustment to the string can be made: at most one bracket can be moved from its original place to any other position in the string. The task is to determine whether, for each string, it is possible to balanced the bracket sequence in 1 move or less. Return an array of the size of the dataset, where the j^th integer is 1 if the string can be converted into a balanced string, and 0 otherwise.
Note: A string s is a balanced bracket sequence if:
Function
isConvertibleData(dataset: String[]) → int[]
Complete the function isConvertibleData in the editor.
isConvertibleData takes the following parameter(s):
String[] dataset: the dataset where each string contains characters ')' and '('
Returns
int[]: an array of integers, where the j^th integer is 1 if the corresponding string can be transformed into a balanced bracket sequence and 0 otherwise
૮꒰ ˶• ༝ •˶꒱ა ♡ Credit to Charlotte
Examples
Example 1
dataset = [")(", "(()", "()"]return = [1, 0, 1]Constraints
- 1 ≤ n ≤ 2 * 10^5
- 1 ≤ |dataset[i]| ≤ 2 * 10^5
- n ≤ Σ|dataset[i]| ≤ 2 * 10^5
- It is guaranteed that each string dataset[i] consists of characters '(' and ')' only
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026