0

Spy life fails test cases 3 & 5

The code for spy life works fine for test cases 1, 2 & 4, but the it fails hidden cases 3 & 5. But I don't know what I need to fix! I would really appreciate if I get to know where I went wrong. https://code.sololearn.com/cA24A0a226A2/?ref=app

20th May 2021, 5:38 AM
Md Shahriar Rahman
Md Shahriar Rahman - avatar
3 Respostas
+ 2
Try this instead; for (int i = length - 1; i >= 0; i--) { *(r + k) = *(s + i); k++; } Or just loop over the original string in reverse and only output the char if it is a-z || A-Z || ' '
20th May 2021, 6:58 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Changing to; *(r + k) = *(s + i); Simply fills the r array from the 0th index up starting with the last char of the string and ending with the first, flipping the string. Where the prior was getting the first char of the string and placing it at the nth position effectively backfilling the r array instead, but was missing the 0th index due to the condition of the for loop. "dlroW olleH" Would result in "ello World" Where "dlroW olleH@" Would result in "Hello World"
20th May 2021, 12:27 PM
ChaoticDawg
ChaoticDawg - avatar
0
Hi ChaoticDawg I used the first alternative, and it worked fine. But I don't understand, what changes did it make? It would be nice if you elaborate
20th May 2021, 11:50 AM
Md Shahriar Rahman
Md Shahriar Rahman - avatar