Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A bracket is considered to be any one of the following characters: (, ), {, }, [, or ]. Two brackets are considered to be

image text in transcribedimage text in transcribedA bracket is considered to be any one of the following characters: (, ), {, }, [, or ]. Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [], {}, and (). A matching pair of brackets is not balanced if the set of brackets it encloses are not matched. For example, {[(])} is not balanced because the contents in between { and } are not balanced. The pair of square brackets encloses a single, unbalanced opening bracket, (, and the pair of parentheses encloses a single, unbalanced closing square bracket, ]. By this logic, we say a sequence of brackets is balanced if the following conditions are met: It contains no unmatched brackets. The subset of brackets enclosed within the confines of a matched pair of brackets is also a matched pair of brackets. Given strings of brackets, determine whether each sequence of brackets is balanced. If a string is balanced, return YES. Otherwise, return NO.

n/python 2 3 import math 4 import os 5 import random 6 import re 7import sys 10 # Complete the braces function below . 12 13 def braces (values): 14 15 name main 17 18 19 20 21 fptr open (os.environ[ 'OUTPUT_PATH'], 'w') values count = int( raw input() values = [ ] 23 24 25 26 27 28 29 30 31 for_in xrange (values_count): values_item- raw_input () values.append (values item) res - braces (values) fptr.write( ' '.join(res)) fptr.write(' ') Braces You are designing a compiler for a C++ program and need to check that braces in any given file are balanced Braces in a string are considered to be balanced if the following criteria are met . All braces must be closed. Braces come in pairs of the form (), 0 and . The left brace opens the pair, and the right one closes it. In any set of nested braces, the braces between any pair must be closed For example, I)l is a valid grouping of braces but [K) is not Function Description Complete the function braces in the editor below. The function must return an array of strings where the string at each index i denotes whether or not the braces were b "YES" or "NO" aligned with their indexes in values. braces has the following parameter(s): values/valueso...valuesn-1: an array of strings to analyze Constraints 1sns 15 1 s length of values,s 100 It is guaranteed that each values, consists of ,), , and only Input Format For Custom Testing Sample Case 0 Sample Input For Custom Testing 0) Sample Output YES

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions