testcase 2&3 are giving wrong answers.is anything wrong with my code?
Tricky_Permutation
Hello @rajukumarbhui,
-
Your code would not work properly when there are odd numbers of repetitions of any permutation.
You are comparing i with i-1, then erasing ith copy if satisfies the condition and finally incrementing the value of i. This is causing problem.
Reason:
After erasing the ith element the (i+1)th element becomes the ith element.
Solution:
decrement after erase statement inside the if block.
Example:
AAA
Expected Output:
AAA
Your Output:
AAA
AAA
AAA -
Your code is causing TLE for large test cases like:
Reason:
Large no. of recursive calls.
Solution:
Try to reduce the recursive calls
You can follow the following approach:
https://ide.codingblocks.com/s/140893
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.