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 parts of the form (), {}, 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, [{}] is a valid grouping of braces. The string [{]} is not because tehre is a closing ] while the nested ( is not closed.

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 balanced in values[i]. The array should consist of strings YES or NO aligned with their indices in values.

braces has the following parameter(s):

values[values[0],...values[n-1]]: an array of strings to analyze
// Complete the braces function below.
vector< string > braces(vector< string > values) {

}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.