CHEFFLR why is my python code wrong?

The problem.

I looked at a similar solution and found that it was the same as this one but still mine is always a wrong answer.

My Solution: http://www.codechef.com/viewsolution/4842743
The one that got the right answer. http://www.codechef.com/viewsolution/4806534

Comments suggestions?

Particularly there is no problem with your code. Actually problem is in the input data. After the end of some of the test case there is probably some ‘blank space’ due to which you are getting a WA.

raw_input() in python reads a complete line.
Consider following two test cases:

Test case 1: 'llr ’
Test case 2: ‘llr’

Both are different because string of test case 1 have an additional space character. So in this case ideally you should do nothing, but your code is doubling x here also. So it will alter x even if it was not required.

What you can do is, put checks for both l and r, and change x only if the current character is either ‘l’ or ‘r’ else do nothing.

I have made slight changes in your code, hope it works ! link

1 Like
//