Last test case is showing wrong answer. Please help.
Recursion-Dictionary Order(Larger) doubt1
Hello @Rooopak_Sharma,
- You need not to swap back the characters.
- There is no requirement of of sorting in this question, thus you can do this question without using the vector or any extra memory.
Modified Code:
Hope, this would help.
I understand that we are not passing the string by reference that’s why there is no need for swap back. But if pass by reference like string &s then after swapping back it shows different output. Why is that happening ?
-
If you’ll pass the string by reference and would remove the second swap statement,
then also you’ll get different output as this would cause the changes made in one recursive call to persist in other also. -
If you’ll use the second swap statement, then it will produce the output in the order, that was produced by your previous code.
Use the below code to understand this better:
If you still don’t get it,
I would suggest you to take a sample input and dry run that on both the programs to understand the flow.
Hope, this would help.
Give a like, if you are satisfied.
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.