Question: Need Python code for the following function: You are designing a compiler for programming language and checking that braces in any given file are balanced.
Need Python code for the following function:
You are designing a compiler for programming language and checking that braces in any given file are balanced.
Braces in a string are considered to be balanced if the following criteria are met:
1. 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.
2. In any set of nested braces, the braces between any pair must be closed.
For example, [{}] is a valid grouping of braces, but MO is not.
Sample: > balanced_braces("( )")
True
> balanced_braces("( ) ) ")
False
> balanced_braces("{( )) ")
True
> balanced_braces("{) ({ ")
False
> balanced_braces("{)[]()")
True
> balanced_braces("{[)]")
False
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
