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

link to my solution is:


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

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

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

@cubefreak777 @everule1 @cub123 help

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

1 Like

thanks bro got it @anon15316785
:innocent: :innocent: :innocent: :innocent: :innocent: :smiley: :grinning:

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.


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
apply R both sides…
=> R(R(S))=S.
if you apply L both sides…
=> L(L(S))=S.
Hope you’d get it.