Your solution outputs the wrong answer for the following test input:

```
1
<><>
```

1 Like

my code output is 2 whats wrong in that? In question it is given that

For each expression you should output the length of the longest prefix that is valid or 0 if there’s no such a prefix.

Is `<><>`

valid? Note that a string is counted as being a prefix of itself.

1 Like

The answer should be 4 for the input

1

<><>

1 Like

sorry i cannot understand,can you elaborate please

and ofcourse its valid

The test input is

```
1
<><>
```

so the expression is `<><>`

. The prefixes of this expression are as follows:

```
< length 1, not valid
<> length 2, valid
<>< length 3, not valid
<><> length 4, valid
```

The longest valid prefix of the expression is `<><>`

, which is of length 4. Thus, the answer is 4.

3 Likes

thanks brother i got it, i was solving it in wrong way.Thanks for your time

1 Like