Wrong output, ignore how i have printed output

i have done all the necessary changes
you can check them below
Modified Code

if you have any doubt feel free to ask

what was wrong with my code?I understood your code. i coded wxactly how it was shown in one of the videos.

Your mistakes

  1. you need not to call recursion twice
  2. for loop of p should not run only twice

Modified Code with your Approach