# WA in Chef and String

Guys my code is failing in chef and string though all sample test cases are passing and a small change corrects my code i’m not getting

https://www.codechef.com/viewsolution/32354145

plz need ur help urgently
@cubefreak777 @saumyaparikh @shubhamskk @everule1

line 27: s[0] = temp needs to be moved out of the for loop…

@anon11076894
how it will effect the code
it will be assigned every time but at last s[0] will be equals to temp only.

though after this the code is working but i am not getting the logic behind this

s[0] =temp; should be written after the for loop because… you can not change s[0] before it is assigned into s[1].

1 Like

You could use a better approach… which is not iterative
https://www.codechef.com/viewsolution/32348102

1 Like

thanks bro got it @anon15316785

1 Like

@anon15316785 can u explain the logic behind ur code why u have applied only R twice???

R is a function to perform left shift twice(although it should be named as L).
left shift includes adding first letter at the end and removing the first letter from beginning.

@anon15316785

you are doing lshift twice and then ur comparing it with original string

but in the given question we have to apply right shift and left shift both and the compare with each other…

i am not getting this…

see if right shift of a string is equal to left shift, then shift it any way twice it should result in the same string
R(S)=L(S)
apply R both sides…
=> R(R(S))=S.
if you apply L both sides…
=> L(L(S))=S.
Hope you’d get it.