logo CodeStepByStep logo

maxSum

Language/Type: C++ recursion backtracking
Related Links:

Write a function named maxSum that accepts two parameters: a reference to a vector of integers, and an integer target. Your function should return the largest sum we can make using elements in the vector without exceeding the target number. If everything in the vector is larger than the number or the vector is empty, return 0.

You are allowed to modify the vector passed in as the parameter as you compute the answer, as long as you restore it to its original form by the time the overall call is finished. Do not use any loops in solving this problem. Your code should use recursive backtracking.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.