help in question compiler and parser

the link to the problem is :-https://www.codechef.com/problems/COMPILER
in that my doubt is how

testcase A:- <>>> (valid) output: 2

testcase B:- <<<> (invalid) output: 0

For test case A, consider the possible prefixes of <>>>:

< is not valid - no matching >

<> is valid

<>> is not valid - too many > characters

<>>> is not valid - too many > characters

The longest valid prefix of <>>> has length 2. So the required output is 2.

For test case B there are no valid prefixes. So the required output is 0.

1 Like

can you explain what longest prefix means i think i am to getting the proper meaning of it

A prefix of a string is a sub-string starting at the beginning of a string.
“c”, “co”, “cod”, “code” are all prefixes of “codechef”.
“chef” is not a prefix of “codechef” because it doesn’t start at the beginning.

Longest means what it says.

1 Like