Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.

Commit 835857a

Browse files
committed
Create largest_sum_contiguous_subarray.cpp
1 parent b00733e commit 835857a

File tree

7 files changed

+235
-0
lines changed

7 files changed

+235
-0
lines changed

.idea/cpp.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 168 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Author : AMEY GONDHALEKAR
3+
*/
4+
5+
#include<bits/stdc++.h>
6+
#define blue ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
7+
using namespace std;
8+
9+
int maxSubArraySum(int arr[], int size)
10+
{
11+
int maxsofar = arr[0];
12+
int currentmax = arr[0];
13+
14+
for (int i = 1; i < size; i++)
15+
{
16+
currentmax = max(arr[i], currentmax+arr[i]);
17+
maxsofar = max(maxsofar, currentmax);
18+
}
19+
return maxsofar;
20+
}
21+
22+
23+
int main()
24+
{
25+
blue;
26+
int arr[] = {6,-2, -1, 5, -1, -4, 1, 6, -2};
27+
int n = sizeof(arr)/sizeof(arr[0]);
28+
int sum = maxSubArraySum(arr, n);
29+
cout << "Maximum contiguous sum is " << sum;
30+
return 0;
31+
}

0 commit comments

Comments
 (0)