Answer-C
Logic- For a given string, do foll-
1. Do push operation on every "(", until you see a ")" then goto step 2.
2. On seeing ")" do pop operation, until you see a "(" then goto step 1.
if(arr[i]==’)’ && s.empty()){
The case when there is nothing to pop[bcz s.empty() returns true] in step 2 and you see a ")" in original string.
example of such unbalanced string--> "())" or more simple case is when original string is just--> ")"
}
else if(arr[i]==’)’ && !s.empty()){
s.pop(); // Step 2 performed.
}
else if(arr[i]==’(’){
s.push(arr[i]); // Step 1 performed.
}