Let’s say we’ve got an array of integers:
int array = {5, 7, 4, 4, 2}
int x=10
The output would be:
10 //(4,4,2)
What’s the fastest way to achieve this output?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are dealing with a Subset Sum Problem (assuming you don’t want contiguous sub-array).
The problem is NP-Complete, and there is no known polynomial solution to it (and the general assumption is that one does not exist, but it is not proven yet)
However, there is a pseudo polynomial solution, using Dynamic Programming.