Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05bc7c4

Browse filesBrowse files
authored
Add files via upload
1 parent 74a31e9 commit 05bc7c4
Copy full SHA for 05bc7c4

File tree

1 file changed

+26
-0
lines changed
Filter options

1 file changed

+26
-0
lines changed

‎best_approach/kadane`s algorithum.cpp

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef vector<int> vi;
8+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
9+
/* -----------------------------------------------------------------------------------*/
10+
11+
int main()
12+
{
13+
pan;
14+
int n;
15+
cin>>n;
16+
vi v(n,0);
17+
for(auto &s:v)
18+
cin>>s;
19+
int best=0,maxo=0;
20+
for(int i=0;i<n;i++)
21+
{
22+
maxo=max(maxo+v[i],v[i]);
23+
best=max(best,maxo);
24+
}
25+
cout<<"maximum subarray is "<<best<<endl;
26+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.