COMPILER - Editorial

combination of statements

char* a[500];
// ...

is strange isn’t it?

1 Like

i used to work on Turbo c++ and it used to work on it.
and also i am new to codeshef.
But Yes It seems strange,,
its working now but ,
time limit exceed,
but i m trying to develop better logic.

You was kind of lucky, your code is not working on ideone I had to change

Scanner s = new Scanner(;
String str = s.nextLine();


//Scanner s = new Scanner(;
String str = rea.nextLine();

and the code returns 0 4 0 for input from problem statement , can you fork it and fix it on ideone?

Your code is not working on ideone, can you fix it? I used your last submission in practice…

try this test case <<>.The answer should be 0 , but ur code gives 2.

why so coz <<> last two brackets are matching which is the case with the official test case of <>>> which gives 2 as output.
plz clarify it :frowning:

you should output the length of the longest prefix

1 Like

thanku got it :stuck_out_tongue:

ad hoc means something that is not known in advance

ANswer for ><<>> should be 0

Why so ?? I can see that I have valid string of length 4 here

Read the problem statement carefully it has asked for length of longest valid ‘prefix’ , so the expression must start with ‘<’. Hope it helps!

They have asked “Prefix”. Read question again. Even first ‘>’ gives answer 0 as there is no valid prefix. There is no need to check further.
is my code, please let me know where’s the mistake.
I tried various test cases and they display correct output. I used pair parentheses algorithm to solve it and have then multiplied the count object by 2 to get the output.

Can someone plz point out the mistake here… i do not understand y this is giving WA.

I am getting the wrong answer, plz explain to me why.


#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std ;

int main(void){
    stack<char> mystack;
    int t;
    int i=0,ans=0;
    string ch;
    int l;
               // cout<<mystack.empty()<<endl;

        else if(!mystack.empty() and ch[i]=='>'){
        else if(mystack.empty() and ch[i]=='>'){

i am also trying to find same thing if you get ans plz tell me to

Can someone plz tell me why i am getting WA ! which test case i am missing ?

How my solution is wrong ?

> #include<iostream>
> #include<stack>
> #include<vector>
> using namespace std;
> int main()
> {
>     int t;
>     vector<int> ans;
>     cin>>t;
>     while(t--)
>     {
>         stack<char> expr;
>         string str;
>         cin>>str;
>         int sum=0;
>         for(int i=0;i<str.length();i++)
>         {
>             if(str[i]=='<')
>                 expr.push(str[i]);
>             else if(!expr.empty())
>             {
>                 expr.pop();
>                 sum+=2;
>             }
>             else
>                 break;
>         }
>         ans.push_back(sum);
>     }
>     for(auto i=ans.begin();i!=ans.end();i++)
>         cout<<*i<<"\n";
>     return 0;
> }

The answer is correct. It should be 0, since there are no "lapin"s at the prefix.

1 Like