Given a sequence consisting of parentheses determine


Given a sequence consisting of parentheses, determine whether the expression is balanced. A sequence of parentheses is balanced if every open parentheses can be paired uniquely with a closed parentheses 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 parentheses. {[(])} - This is not a balanced parentheses. Input Format The first line of input contains the number of test cases, . Each test case consists of a single line, , the sequence of parentheses. 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. Sample Input 3 {[()]} {[(])} {{[[(())]]}} Sample Output YES NO YES

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Given a sequence consisting of parentheses determine
Reference No:- TGS01397109

Expected delivery within 24 Hours