My code is passing all the given sample input test cases but it gives me a wrong answer.Could someone please tell me where I am going wrong? Thanks in advance.
@roshi: your algorithm is incorrect and may be correct for only few cases because try this small test case:
1
3 5
2
3
4
your algorithm returns No but answer is Yes(2+3). you should find all the subsets sum from the given array and verify whether any subset sum is equal to the given amount or not if it is equal print Yes else No.
example is my sample test case
subsets of the given array is {2},{3},{4},{2,3},{2,4},{3,4},{2,3,4}
from the above subsets 4th subset matches sum equal to 5 hence returns true but your algorithm first subtracts 4 from 5 remaining 1 and there is no 1 and hence returns No
If this is helpful to you upvote and accept my answer. Thank you happy coding