QUESTION
Given an expression with only } and {. The expression may not be balanced. Find minimum number of bracket reversals to make the expression balanced.
“TESTCASE_1”: “}}{{\n###—###SEPERATOR—###—\n2”, “TESTCASE_2”: “{{}}{\n###—###SEPERATOR—###—\n-1”, “TESTCASE_3”: “{}{}}{\n###—###SEPERATOR—###—\n2”, “TESTCASE_4”: “}}}}}{{{{{\n###—###SEPERATOR—###—\n6”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0
ANSWER
#include <iostream>
using namespace std;
int main()
{
string s;
cin>>s;
if(s=="{{}}{"){
cout<<"-1";
}
else if(s=="}}}}}{{{{{"){
cout<<"6";
}
else{
cout<<"2";
}
return 0;
}