diff --git a/README.md b/README.md index c183e03..11518b5 100644 --- a/README.md +++ b/README.md @@ -162,4 +162,14 @@ The majority element is the element that appears more than ⌊n / 2⌋ times. Yo Input :- [2,3,3,2,2] Output :- 2 -``` \ No newline at end of file +``` + +## [Find sum of Maximum sum subarray](https://leetcode.com/problems/maximum-subarray/) + +``` +Given an array of integers containing positive as well as negative integers. Find the sum of subarray which has maximum sum, in the given array. + +Input : 2,-3,4,5,-1 +Output : 9 (Subarray - [2,3]) + +``` diff --git a/find-sum-of-maximum-sum-subarray/kadanes-algorithm.cpp b/find-sum-of-maximum-sum-subarray/kadanes-algorithm.cpp new file mode 100644 index 0000000..b810ac1 --- /dev/null +++ b/find-sum-of-maximum-sum-subarray/kadanes-algorithm.cpp @@ -0,0 +1,25 @@ +/* + +This is O(N) in time complexity. + +*/ + +#include +using namespace std; + +int maxSubArray(vector& arr) { + int curr_sum=0, max_sum=INT_MIN; + for(int i=0; i arr{2,-3,4,5,-1}; + int res = maxSubArray(arr); + cout<<"Sum of Maximum sum subarray is "<