Question: Create a function max_sub_sum that takes an array list of integers of size n > 0 as arguments and returns the maximum subarray sum in

Create a function max_sub_sum that takes an array list of integers of size n > 0 as arguments and returns the maximum subarray sum in list. A maximum subarray sum is defined as the largest possible sum of contiguous elements within the input array. For example, for the sequence [-2, -4, 3, -1, 5, 6, -7, -2, 4, -3, 2], the maximum subarray sum is 13, because the sum of elements in subarray [3, -1, 5, 6] is the largest among all possible subarrays. If all elements in list are negatives, your function must return 0.

this is the function and its parameters

unsigned int max_sub_sum(const int *list, unsigned int n);

It must be written in C++ and only include cmath and iostream

I only need the function but if you want to write a main some test parameters are

  • {4, -2, -8, 5, -2, 7, 7, 2, -6, 5} = 19
  • {555555} = 555555
  • {-55555} = 0
  • {-3, 3} = 3
  • case where the correct sum is the final element in the array. Ex: {-3, -3, -2, -6, -5, 10} = 10
  • case where the correct sum is 1 number (depending on how your implementation this might be already taken care of)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!