Question
C++ Programming ONLY CheckBalancedParentheses (Super Popular Interview Question) You are given a string that contains parentheses ( and ). Determine if the given string is
C++ Programming ONLY
CheckBalancedParentheses (Super Popular Interview Question)
You are given a string that contains parentheses ( and ). Determine if the given string is balanced.
Balanced parentheses means that each opening symbol has a corresponding closing symbol and the pairs of parentheses are properly nested. Consider the following correctly balanced strings of parentheses:
These are also the test cases :
TestTrue1: ()
TestTrue2: (())
TestTrue3: (()()()())
TestTrue4: (((())))
TestTrue5: (()((())()))
Compare those with the following, which are NOT balanced:
TestFalse1: (
TestFalse2: )
TestFalse3: ((((((())
TestFalse4: ()))
TestFalse5: (()()(()
Guidelines
Do not mess with the function declaration
Only code within the CheckBalancedParentheses function
To test your code run make CheckBalancedParenthesesTest.
Part 2: CheckBalancedAll
Now the string can include other characters: brackets [ ] and curly braces { }. A ( can only balance with ), a [ can only balance with ], and a { can only balance with }. Your job is to make your code from the previous problem to work with this extended use case.
These are cases where it is balanced:
These are also the test cases :
TestTrue1: [()]{}{[()()]()}
TestTrue2: {[()]}
TestTrue3: {{}[][()]}
Compare those with the following, which are NOT balanced:
TestFalse1: [(])
TestFalse2: (}{}][])
TestFalse3: []({)
Guidelines
Do not mess with the function declaration
Only code within the CheckBalancedAll function
To test your code run make CheckBalancedAllTest.
HERE IS HEADER FILE:
#ifndef CHECKBALANCED_H #define CHECKBALANCED_H
#include
bool CheckBalancedParentheses(std::string input);
bool CheckBalancedAll(std::string input);
#endif
HERE IS CPP FILE:
#include "CheckBalanced.h" #include
using namespace std;
bool CheckBalancedParentheses(std::string input) { stack
return true; }
bool CheckBalancedAll(std::string input) { stack
return true; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started