Split Array (Recursion)

I’m not able to think for the approach of this question. Please guide me to think for the approach for this type of questions?

hi @mvermav19
Approach:

generate all subsequences whose sum is half of totalSum
then print the subsequence and remaining elements from array

now try to implement this

I tried to implement this approach.
Here is my code:


But i don’t know why it’s not working?

hi @mvermav19
There is no code saved at the link u shared… kindly save ur code and reshare the link…

ooh okay!


this is the code sir

hi @mvermav19
refer this https://www.geeksforgeeks.org/split-array-two-equal-sum-subarrays/
Hope it will clear ur doubt…

Actually I’m not getting it! can u please explain it a bit?

ok… try this -->


what i have done is first generated all subsequences, and then check if sum is equal to half of sum of all elements… if yes, then print the corresponding ans…

hi @mvermav19
I hope it’s clear now??

what is set here in this code?

set is a data structure only for storing data… i have used it for easy checking of what elements are in other subsequence in base case…
I have replaced set with vector if u are facing any difficulty–>

okay, understood sir.
Thank you!

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.