#C14607. Valid Bracket Sequence
Valid Bracket Sequence
Valid Bracket Sequence
Given a string s consisting solely of bracket characters: ()
, []
, {}
, and , determine whether the brackets are properly nested and matched. In other words, check whether for every opening bracket there is a corresponding closing bracket in the correct order.
The problem can be formally expressed as: $$ \text{isValid}(s) = \begin{cases} \text{True} & \text{if } s \text{ is a valid bracket sequence,} \\ \text{False} & \text{otherwise.} \end{cases} $$
Examples:
- Input: "([]){}" → Output: True
- Input: "([)]" → Output: False
- Input: "" → Output: True
inputFormat
The input is provided via standard input (stdin) as a single line containing the string s
composed exclusively of the characters ()
, []
, {}
, and .
outputFormat
Output a single line to standard output (stdout) containing either True
if the bracket sequence is valid or False
if it is not.
([]){}
True