Frage im Vorstellungsgespräch bei Thoughtworks

check for balanced parentheses without using stack

Antwort im Vorstellungsgespräch

Anonym

16. Juli 2017

We can simply use a counter for both '(' and ')' check if the difference is 0. Or ++counter for '(' and --counter for ')' and if at any time counter<0, parenthesis are not balanced.