Question d’entretien chez Ooyala

given a string,which is filled with either "(" or ")", for example "(())()())", write a function to check if the string is "proper". A "proper" string means if there is a "(" in the string, there should be a ")" which corresponds to the "(" in the string. For example, "))()("

Réponses aux questions d'entretien

Utilisateur anonyme

28 mars 2011

you can traverse through the string in a loop and increment a counter on occurrence of '(' and decrement on occurrence of ')' .Return false if counter becomes negative anytime in the loop.

3

Utilisateur anonyme

24 déc. 2013

Just a single stack, pop for ')' and push for '('. if isEmpty() when you encounter ')' means string is not proper

Utilisateur anonyme

17 déc. 2010

two sub tasks. One is to check if the number of "(" and ")" in the entire string are equal. The other task is to check the number of "(" is always no less than the number of ")" when traversal the string from the head of string to the end.