which test cases my code does not satisfy.

i wrote this code but it is giving wrong answers in a few test cases . what am i doing in this code is this:-

take input as string
calculate length of string.
declare an array of size length +1.
store values in the array as per sign.
arr[0] is set at 1 by default.
now count the no. of unique nos in the array by storing unique elements in a map.

pls help.

This case:-



The answer should be 5.

But your code will output:7


The logic behind correct answer is:


(Just count maximum consecutive occurrences of ‘<’ or ‘>’ ignoring all '='and add one to it, that will be the final answer, because in any case the maximum number of numbers required will never go above that.)


Actually, I too was bothered by this problem. The problem seems to be a blindspot or oversight during the understanding of the instructions. It got some relation with the evaluation of the logic of ‘>’. To give an example:


Here, if you apply your function, you will get:


But in reality, based on minimizing the upper limit, it should be:

1<2<3<4<5>4>1<2>3>4>5<6 or 1<2<3<4<5>2>1<2>3>4>5<6

both of which gives 6 as the maximum of P. Another special case would be:


Which gives:


that should be:


Hope this helps.

1 Like