DSA learning series week 2 4th question.
compiler and parsers.
I really don’t understand the problem with my code. can somebody please help.
#include
#include
#include
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
string str;
cin >> str;
int n = str.length();
stack<char> s;
int len = 0;
int max = 0;
int l = 0;
for(int i = 0 ; i < n ; i++){
if(str[i] == '<'){
s.push('<');
}
else if(str[i] == '>'){
if(s.empty()){
len = 0;
}
else {
s.pop();
len += 2;
if(len > max) max = len;
}
}
}
cout << max <<"\n";
}
return 0;
}
Atleast give me a test case where my code fails give the right answer. Any help is really appreciated