(
inti = 0; i < arr.size(); i++) {
39 intcurrent_max = arr[0], max_so_far = arr[0], current_min = arr[0], min_so_far = arr[0];
42 for(
inti = 1; i < arr.size(); i++) {
44current_max = std::max(current_max + arr[i], arr[i]);
45max_so_far = std::max(max_so_far, current_max);
48current_min = std::min(current_min + arr[i], arr[i]);
49min_so_far = std::min(min_so_far, current_min);
52 if(min_so_far == sum)
56 returnstd::max(max_so_far, sum - min_so_far);
70std::vector<int> arr = {8, -8, 9, -9, 10, -11, 12};
73arr = {8, -8, 10, -9, 10, -11, 12};
76std::cout <<
"All tests have successfully passed!\n";
static void test()
Self-test implementation.
int main()
Main function.
Dynamic Programming algorithms.
int maxCircularSum(std::vector< int > &arr)
returns the maximum contiguous circular sum of an array
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4