#K12971. Valid Parentheses
Valid Parentheses
Valid Parentheses
This problem asks you to determine if a given string of parentheses is valid. A string is considered valid if:
- Every opening bracket is closed by the same type of bracket.
- Brackets are closed in the correct order.
The allowed parentheses are: ()
, []
, and {}
. In mathematical terms, a valid expression satisfies $$\forall\,open,\,close,\,open = close$$ and respects proper nesting.
For example, the string [{()}]
is valid, while [(])
is invalid.
inputFormat
The input consists of a single line containing a string s
composed solely of the characters (
, )
, [
, ]
, {
, and }
.
outputFormat
Output a single line containing Yes
if the string is a valid set of parentheses, otherwise output No
.
[{()}]
Yes