COMPILER - Editorial

I can’t see anything incorrect about it - are you sure you’ve submitted it correctly? Can you link to the submission that gives WA?

Edit:

None of your six submissions:

https://www.codechef.com/viewsolution/32933182
https://www.codechef.com/viewsolution/32932987
https://www.codechef.com/viewsolution/32932685
https://www.codechef.com/viewsolution/32931702
https://www.codechef.com/viewsolution/32931591
https://www.codechef.com/viewsolution/32931353

match the code given in your link.

1 Like

what should be the output for this testcase?
2?
https://www.codechef.com/viewsolution/33184548
This is my code. Where am I going wrong?
Please help.

The answer for the test input:

1
<><

should be 2, yes.

Your solution fails on the following testcase:

1
<<><

I think I passed these two testcases. Still failing.
https://www.codechef.com/viewsolution/33186008

1
>

(your code has an out-of-bounds access on this test input).

1 Like

ok

already consider

While solving the problem, I had a doubt, will be grateful if answered. What should be the output for the input, “<><<<>>>”?

Can anyone help me with this code, returning WA :
My code

Your code doesn’t works on this test case:

<>><

Your output- 0
Correct output- 2

1 Like

Input
4
<<>>>><>
<><<<<>
<>>>
<<><>>

output
4
2
2
6

check these

Stack solution in python: 991lTH - Online Python Interpreter & Debugging Tool - Ideone.com

it is giving me wa ,can u plss help out me here
here is code:
#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t–){
string str;
cin>>str;
class Node{
public:
char value;
int indexvalue;
};
std::stack f;

    int start=0;
    int end=0;
    int k=-1;
    for(int i=0;i<str.size();i++){
        char s = str[i];
        
        if(i == 0){
            if(s == '>'){
                break;
            }
        }
     if(s=='<'){
         Node n;
         n.value=s;
         n.indexvalue=i;
         f.push(n);
     }
     else{
         if(!f.empty()){
         Node tempnode=f.top();
         f.pop();
         int tempstart=tempnode.indexvalue;
         int tempend=i;
         int tempk=tempend-tempstart;
         if(tempk>k){
             k=tempk;
              start=tempstart;
             end=tempend;
         }
         }
        
         
     }
     
    }
    cout<<k+1<<endl;
    
}

}

why this code gives WA?
https://www.codechef.com/viewsolution/43619514

It fails on the sample input.

2 Likes

https://www.codechef.com/viewsolution/43631671
still gives me WA although I tested almost every input

please tell me why i am getting wa ;(

#include <bits/stdc++.h>
using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t–)
{
string s;
cin>>s;
long n=s.size();
stack st;
long count=0,max=0;
for(long i=0;i<n;i++)
{
if(s[i]==’<’)
st.push(s[i]);
else if(st.empty())
st.push(s[i]);
else
{
if(s[i]==’>’ and st.top()==’<’)
{
st.pop();
count=count+2;
}
else if(s[i]==’>’ and st.top()!=’<’)
count=0;
else
{
st.push(s[i]);
}
}
if(count>max) max =count;
}
// long st_size=st.size();
// long prefix=n-st_size;
// cout<<prefix<<"\n";
cout<<max<<"\n";
}

// your code goes here
return 0;

}

please help me out to debug it

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

okay