#C12289. Valid Braces Checker
Valid Braces Checker
Valid Braces Checker
Given a string s containing any characters, your task is to determine whether the braces (parentheses, brackets, and curly braces) in s are properly matched and nested.
A valid string should satisfy:
- Every opening brace has a corresponding closing brace of the same type.
- Braces must be closed in the correct order.
This can be formally expressed by the following condition: if we denote the set of braces as \(\{(, ), {, }, [, ]\}\), then the string is valid if after scanning from left to right, every encountered opening brace has a corresponding closing brace in the correct order (i.e. stack
behavior).
Examples:
Input: a(b)c[d]{e} Output: True</p>Input: ([)] Output: False
inputFormat
The input is provided via stdin and consists of a single line containing the string s (which may include spaces and any printable characters).
Constraints:
- The length of s is between 0 and 1000.
outputFormat
The output should be written to stdout and is either True
or False
(without quotes), indicating whether the string has valid matching and nesting of braces.
a(b)c[d]{e}
True