#K72417. Valid Parentheses Checker
Valid Parentheses Checker
Valid Parentheses Checker
You are given a string s
consisting solely of the characters (')
, {'}
and [']
. Your task is to determine if the string is valid. A valid string meets the following criteria:
- Every opening bracket must have a corresponding closing bracket of the same type.
- Opening brackets must be closed in the correct order (i.e. last opened, first closed).
Formally, a string s
is considered valid if it satisfies:
Print YES
if the string is valid, otherwise print NO
.
inputFormat
The input consists of a single line containing a string s
that comprises only the characters '(', ')', '{', '}', '[' and ']'. The string may be empty.
outputFormat
Output a single line: YES
if the input string has valid parentheses matching and proper nesting, otherwise NO
.
{[()]}
YES