Problem MANYCHEF : whats the issue?

http://www.codechef.com/viewsolution/1745517

this is the accepted solution of the problem I got TLE on my submission so I modified the code which is exactly similar to the above one but I’m still getting TLE.

My solution : http://www.codechef.com/viewsolution/1760327

Please tell me how is this happening ?

@yashvardhan90 :
i=n-1;
if( a[i]==β€˜F’ || a[i]==’?’)
if( a[i-1]==β€˜E’ || a[i-1]==’?’)
if( a[i-2]==β€˜H’ || a[i-2]==’?’)
if( a[i-3]==β€˜C’ || a[i-3]==’?’)

The top most line β€œi=n-1” is the β€œculprit” . Why should it be here inside the while loop ???
Your loop never ends , for say a string of size 20 .

1 Like