Problem · String

Is Balanced String

MediumGooglePHONE SCREEN
See Google hiring insights

Write a function to check if the given input string is balanced or not. The input string will contain parentheses and digits.

whenever digit is occurred you need to remove digit number left side paranathesis in any order (ex: if digit is 2 you need to remove 2 paranthesis from left side means if inp == )(1, either I can remove ( or ) left side of 1). string is balanced if opening paranthesis is equal to closing (ex: (()), ()(), ()), treat each digit seperately if 11 is present in input treat them as 2 ones.

pps: 1 == true, 0 == false

Examples
01 · Example 1
s = "(()1(1)) "
return = 1
:}
02 · Example 2
s = ")1()"
return = 1
o.o
03 · Example 3
s = ")(1))"
return = 0
:3
More Google problems
drafts saved locally
public int isBalancedString(String s) {
  // write your code here
}
s"(()1(1)) "
expected1
sign in to submit