Java task (with Stacks):
Given a sequence consisting of parentheses, determine whether the expression is balanced. A sequence of parentheses is balanced if every open parenthesis can be paired uniquely with a closed parenthesis that occurs after the former. Also, the interval between them must be balanced. You will be given three types of parentheses: (, {, and [.
{[()]} - This is a balanced parenthesis.
{[(])} - This is not a balanced parenthesis.
Input Format: Each input consists of a single line, S, the sequence of parentheses.
Constraints:
1 ≤ lens ≤ 1000, where lens is the length of the sequence.
Each character of the sequence will be one of {, }, (, ), [, ].
Output Format: For each test case, print on a new line "YES" if the parentheses are balanced. Otherwise, print "NO". Do not print the quotes.
Input
|
Output
|
{[()]}
|
YES
|
{[(])}
|
NO
|
{{[[(())]]}}
|
YES
|