A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/db/dfb/maximum__circular__subarray_8cpp_source.html below:

TheAlgorithms/C++: dynamic_programming/maximum_circular_subarray.cpp Source File

Go to the documentation of this file. 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);

70

std::vector<int> arr = {8, -8, 9, -9, 10, -11, 12};

73

arr = {8, -8, 10, -9, 10, -11, 12};

76

std::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