34 for (
int i = 0; i < arr.size(); i++) {
39 int current_max = arr[0], max_so_far = arr[0], current_min = arr[0], min_so_far = arr[0];
42 for (
int i = 1; i < arr.size(); i++) {
44 current_max = std::max(current_max + arr[i], arr[i]);
45 max_so_far = std::max(max_so_far, current_max);
48 current_min = std::min(current_min + arr[i], arr[i]);
49 min_so_far = std::min(min_so_far, current_min);
52 if (min_so_far == sum)
56 return std::max(max_so_far, sum - min_so_far);
71 std::vector<int> arr = {8, -8, 9, -9, 10, -11, 12};
74 arr = {8, -8, 10, -9, 10, -11, 12};
77 std::cout <<
"All tests have successfully passed!\n";