Thankyou so much…your help made me come up with a few different ways, although all are WA.
Previously, I thought we have to o/p longest prefix even if it was an invalid statement…but now i dont know if i was wrong!!
Taking your help i came up with the following, which returns 0 if its an invalid statement:
but this still shows WA…
Then i saw the example which says <>>> should o/p 2, but this is an invalid statement…
Could you explain the problem statement to me, what it wants…
Does it mean every < should have a > but every > need not have a <
I’ve been spending too much time on this and cant seem to get moving without getting this right,could you please help me one last time and explain the problem statement properly.
The problem statement says that for every ‘<’ symbol there should be one ‘>’ symbol but it is not mandatory that it should occur after that, it can occur immediately as well as somewhere in the given string, and for ‘>’ symbol it should always have one ‘<’ symbol corresponding to it.
And now about this test case <>>> as you can see according to the problem statement we want that ‘<’ symbol should have one ‘>’ so it is there and about this ‘>’ symbol should have one corresponding ‘<’ it is present just before >. That’s why this testcase is valid.
Hello. Okay so now i think i understand. But let me be sure, so
<<>>>> should return 4 <>< should return 2 <<> should return 0 and <><<>> should return 2 right?
With this understanding i came up with this: #include <stdio.h>
Oh god, finally!
Thank you so much, it took me 15 wrong submissions and 3 days to get it right. You solved the last bit of doubt. Much of the problem was i couldn’t understand the problem statement. No wonder this simple problem had so many wrong submissions.
Thank you so much for your quick help. Can finally sleep in peace tonight.