COMPILER WA Plz help!

Can somebody give me a testcase where my code is giving WA or tell me what is wrong in my code ?? Plz…
My sol: CodeChef: Practical coding for everyone

Thanks
Aditya

@sidhant007 @adhyyan1252 @socho @anon38711361 @vijju123_adm @taran_1407 @kuruma

For following test-cases your program is giving incorrect output:

3
<<<>
<<<<<<<>
<>>><><><>

Your Code Output:

2
2
8

Correct Output:

0
0
2
2 Likes

thanks @striker22 , i had interpreted the question wrongly. Now the question is clear to me.

@striker22 But why in sample testcases the 3rd one’s output is 2 . I think it should be 0.
Plz explain.

Input:
3
<<>>
<
<>>>

Output:
4
0
2

Because the problem is asking you to compute the length of the longest balanced prefix.
In the 3rd one longest balanced prefix is <> and its length is 2.

Agree, but some > tags did not have opening tags is this valid.

Read the problem statement again and carefully. A string consist of < and > is said to be balanced if for every < there exist >. The problem is asking for longest balanced prefix.

1 Like

Ok now i got it. Thanks a lot.