Subset sum easy problem help me in correction


this is code i made using brute force approach but i didnt get the answer pls correct me where i am wrong this is the brute force approach i used correct me in this too


this is code i made using recursion but not pass the test cases pls correct me in both the codes and this also

Your brute forces is incorrect because it doesn’t generate all subsets. Use bitmasks to generate them.
I have corrected your recursive implementation. https://ide.codingblocks.com/s/641376
I took an extra variable taken to make sure number of elements selected is not zero when sum is equal to 0.

is it possible sir to improve my brute force approach without using bitmasking

Writing 4 loops is not practical. So no. I would advice you to study bitmasks

1 Like

ok sir now the doubt is resolved

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.