What's wrong with the code?

hello @priyamthakuria27
wait i mm checking

check ur code ->https://ide.codingblocks.com/s/283850

base case should be i==s.size() because c++ string never terminate with \0

and that is why i converted string ans to char * ans.

why is the previous code running with s[i]!=’\0’, then?
there have been many questions where i used \0.

moreover, my code runs on ide.
on submission it shows WA.

i think checker also compares length that why giving WA.

if u want to use string.
then try to resize its length before printing. (may be it works)