#C6198. Valid Bracket Sequence Checker
Valid Bracket Sequence Checker
Valid Bracket Sequence Checker
This problem requires you to determine whether a given sequence of brackets is valid. A bracket sequence is considered valid if every opening bracket has a corresponding closing bracket and the pairs of brackets are properly nested.
Formally, for a string s consisting of characters from the set \(\{ '(', ')', '{', '}', '[', ']' \}\), the sequence is valid if it satisfies the following condition:
\[ \text{A sequence is valid} \iff \text{every opening bracket has a matching closing bracket and the order of the brackets is correct.} \]
For example, the sequences "(())" and "{[()()]}" are valid, while "([)]" and "((()" are not.
inputFormat
The input consists of a single line containing a string s which represents the sequence of brackets.
Input Format:
[s]
outputFormat
Output a single line containing YES
if the bracket sequence is valid, and NO
otherwise.
Output Format:
YES or NO## sample
{[()()]}
YES