Simple Valid Brackets

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 128M

Author:
Problem type

For an extra challenge, check out Valid Brackets!

Determine if the given sequence of round brackets is valid. A sequence of brackets is considered valid if each opening bracket is paired with a closing bracket. The closing bracket can be anywhere in the sequence, as long as it comes after (to the right of) its corresponding pair. For example: ()()(), ((())), (())(), (()()), ()(()) are all valid bracket sequences. However, (()(() is not a valid bracket sequence because not every opening bracket has a closing bracket paired with it.

Input Specification

The first and only line will be a string solely consisting of opening and closing brackets.

Output Specification

Print YES if the sequence is valid according to the conditions stated above, and NO if otherwise.

Sample Input

(()(()))

Sample Output

YES

Comments

There are no comments at the moment.