#K33597. Valid Parentheses Checker
Valid Parentheses Checker
Valid Parentheses Checker
Given a string s that consists solely of the characters (')
, '{' and '}'
, and '[' and ']'
, determine if the input string is valid.
A string is valid if:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
- The string must not contain any characters other than these brackets. In other words, any character outside the set
{ '(', ')', '{', '}', '[', ']' }
makes the string invalid.
An empty string is considered valid.
Formally, if you denote the input string as \( s \), then it is valid if and only if it is empty or it can be written in the form \( s = uv \) such that both u and v are valid, or it can be written as \( s = (t) \), \( s = \{t\} \) or \( s = [t] \) for some valid string \( t \).
inputFormat
The input is provided from standard input and consists of a single line containing the string s. The string will only contain the characters: (')
, ')'
, '{'
, '}'
, '['
, and ']'
.
outputFormat
Output to standard output a single line: True
if the string is valid, and False
otherwise.
True