maximum sum of continuous of sub array

class Solution {
public:
int maxSubArray(vector& nums) {
// most efficient approach 100 ms using kadanes algorithm
int sum=0;
vectorv;
int mx=INT_MIN; // INT_MIN is the min values in whole array //
for(int i=0;i<nums.size();i++)
{
sum=sum+nums[i];
if(mx<sum){
mx=sum;
}
// here mx is varaible which stores MIN val in array
// mx will be updated evry time//
if(sum<0)
sum=0; // if there are any negative values simple ingonre them becoz we want only positive values//
}
return mx;

}

};

Comments (0)