Monday, March 10, 2008

Try out when free

You are given an arbitrarily long string of parentheses i.e. a string comprising of '(' and ')'.

Give an efficient way of finding whether a given string contains a balanced parentheses or not. Note that the string can be of any length.

A string with balanced parentheses is a string containing same number of left parentheses '(' and right parentheses ')'. Also, they must be in correct order i.e. ( ( ) ( ) ) is balanced whereas ( ) ) ( ( ) is not.

No comments: