Valid parentheses || SEGV Error

Question - Link
My code lInk - here
This is my code

I am getting the following run time error. Please help

suggestions - give code .

Code Link - Click here

you code fails for this "(])"
as your code doesnt push ] into stack , so last char ) checks with stk.top() which is ( returns true .

yes, do a dry run first.

You can refer my C++ 0ms Solution

class Solution 
{
public:
    stack<char> st;
    bool isValid(string s) 
    {
            for(int i=0;i<s.length();i++)
            {
                if( (st.size() ==0) &&  (s[i]==')' || s[i]==']' || s[i]=='}' || s[i]=='>')) return false;
              
                if(s[i]=='(' || s[i]=='[' || s[i]=='{' || s[i]=='<')
                {
                    st.push(s[i]);
                }
                else if( (s[i]==')' && st.top()=='(') || (s[i]==']' && st.top()=='[') ||
						 (s[i]=='}' && st.top()=='{') || (s[i]=='>' && st.top()=='<')   ) 
                {
                    st.pop();
                }else return false;
            }
      return st.empty();
    }
};

image