Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Kadane's algo #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kamalbhardwaj
Copy link

Please describe your program and how to run it.
A c++ program that outputs the starting and ending indices of the subarray which has the maximum sum in the array.


What Programming Language?
C++
...language...

cout<<"Enter the elements\n";
for(int i=0;i<n;i++) cin>>arr[i];
int start=0,end=0,sum=0,maxsum=0;
for(int i=0;i<n;i++){ sum+=arr[i]; if(sum<0) { sum=0; start=i+1;} if(sum>maxsum){ maxsum=sum; end=i; } }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite one-line but it might be compressible. I don't see a solution immediately but give it another try!

@wzhouwzhou wzhouwzhou added Lang: C Contributions made in C Lang: C++ Contributions made in C Plus Plus and removed Lang: C Contributions made in C labels Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lang: C++ Contributions made in C Plus Plus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants