Compilers And parsers

Can anyone explain me whati am doing wrong in the code below:
Problem code : COMPILER
#include
#include<bits/stdc++.h>
using namespace std;

int main() {

int t=0;
cin >> t;
while(t--){
   stack<char> st;
    string s;
    cin >> s;
    int i=0;
    int res = 0;
    while(i<s.length()){
     if(s[i]=='<'){
          st.push(s[i]);
     }else if(!st.empty() && s[i]=='>' && st.top()=='<'){
            st.pop();
            res+=2;
     }
     
     i++;
    }
  
   cout << res << endl;
}
return 0;

}

1 Like

I am getting 2 as output which is correct

i think i have miss understood the question

1 Like

Above test case is invalid and my program is returning 2.
Thanks for testcase i understood now

1 Like