Why not use different string to store resulting string instead of making changes in original string?

In worst case: “pipipipipipipipipipipipipipipipi…”, it will take O(n^2) time to convert this by changing this string. But storing and adding results in new string, we can do same task in O(n).

Is there any specific reason of using same string to store the results ??

hi @harshsharmajnv_9b70d236614796d5 here this was done to make it in o(1) space

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Okay, Thanks :grinning: :grinning: