The following code is giving me a runtime error for some reason I'm unable to figure out.
We are iterating over the string a and whenever we encounter a char = (, we push 1 into the stack and whenever we encounter ) we remove an element from the stack.
#include <bits/stdc++.h>
using namespace std;
int main() {
    string a= ")()())";
    stack<int> st;
    for(int z = 0; z < a.length(); z++){
        if(a[z] == '(') st.push(1);
        else st.pop();   
                                                              
        }
    
}
Can someone please explain why is it giving me a runtime error?
 
     
     
    