Can't build logic around returning vector

Things I tried:

  • Passing vector in recursive function as an argument and populating it in each iteration instead of the cout statement.
  • As the return statement is only in if condition, the compiler gives an error if there is no return statement at the end of the function.

Any hint or push in the right direction will be helpful. Thank you.

I see your code got accepted.
Is there any other issue?

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.