Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

print maximum sum subarray

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int  i = 0;i<n;i++){
		cin>>a[i];
	}
	int s = 0;
	int mx = INT_MIN;
	for(int  i =0;i<n;i++){
		s+=a[i];
		if(s<0){
			s=0;
		}
		mx = max(s,mx);
	}
	cout<<mx;
	return 0;
}
 
PREVIOUS NEXT
Tagged: #print #maximum #sum #subarray
ADD COMMENT
Topic
Name
8+2 =