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