#K35802. Balanced Brackets Checker
Balanced Brackets Checker
Balanced Brackets Checker
Given a string S consisting only of the characters '(', ')', '{', '}', '[' and ']', determine if the input string's brackets are balanced.
A string is considered balanced if:
- Every opening bracket is closed by a matching bracket of the same type.
- Brackets are closed in the correct order.
You can think of the problem in terms of the following condition involving a stack: For every opening bracket c, there must be a corresponding closing bracket such that
\( \text{stack.top()} = c \) when a closing bracket is encountered.
If the string is balanced, output YES
, otherwise output NO
.
inputFormat
The input consists of a single line containing the string S
where \(0 \leq |S| \leq 100\).
The string S
contains only the characters '(', ')', '{', '}', '[' and ']'.
outputFormat
Output a single line: YES
if the brackets in the string are balanced, and NO
otherwise.
()[]{}
YES