Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
SubsequenceArray
//clang 3.8.0 #include <iostream> int maximum(int a,int b,int arr[]); int main() { std::cout << "Hello, world!\n"; int arr[] = { 2, -4, 1, 9, -6, 7, -3 }; int n = sizeof(arr) / sizeof(arr[0]); std::cout<<maximum(0,n-1,arr); } int maximum(int low,int high,int arr[]) { int sum=0; if(high== low) return arr[low]; int mid =(low + high)/2; int leftSum=0; for(int i=mid;i>=0;--i){ leftSum+=arr[i]; if(leftSum>sum){ leftSum = sum; } } sum=0; int rightSum=0; for(int i=mid+1;i<high;i++){ rightSum+=arr[i]; if(rightSum>sum){ rightSum = sum; } } int max = std::max(maximum(low,mid,arr),maximum(mid+1,high,arr)); return std::max(max,leftSum+rightSum); }
run
|
edit
|
history
|
help
0
Enum flags operator example
Last Class Quiz - Working with Hash Table
Throttle Example using a circular queue (Push all but 2 less than maxSize; then pop all but 2 of current size)
Test size_t
Template arguments may contain calls to constexpr functions.
isnan_constexpr
Recursive Function Calling Example with Stack Addresses
Balanced Insert Heap Example
hello world
11/18