We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4bc46a7 commit 200e536Copy full SHA for 200e536
classical_algorithms/c++/Kadane_Algorithm.cpp
@@ -0,0 +1,26 @@
1
+//Given an array of intergers. Find the contiguous sub-array with maximum sum.
2
+
3
+#include <bits/stdc++.h>
4
+using namespace std;
5
6
+int main() {
7
+ cout<<"Enter the number of elements for array:\n";
8
+ int n;
9
+ cin>>n;
10
11
+ vector<int>v(n);
12
+ cout<<"Enter the values of the array:\n";
13
+ for(int i=0;i<n;i++){
14
+ cin>>v[i];
15
+ }
16
+ int ans = INT_MIN;
17
+ int sum = 0;
18
19
+ sum = max(v[i], sum + v[i]);
20
+ ans = max(ans, sum);
21
22
23
+ cout<<"The maximum sum of contigous array is: ";
24
+ cout<<ans<<"\n";
25
+ return 0;
26
+}
0 commit comments