Ad
  • Custom User Avatar

    With input of "ab(cd", output should be "ab(cd". But with this you would get "ab". Maybe it would be useful to save last index of where you open parentheses, and in the end of loop, there could be a check if sum == 0. If not, sum += str.substring(savedIndex).