logo CodeStepByStep logo


Language/Type: C++ recursion backtracking
Related Links:
Author: Marty Stepp (on 2016/06/16)

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.

Type your C++ solution code here:

This is a function problem. Write a C++ function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.