Kadane algorithm

what if we just have negative numbers. In that case our maximum sum will always be zero which is the wrong answer

hi @jaichaturvedi1861_8ca88690b823e07a u need to handle the case take max(cs,a[i])
refer this :

int maxSubarraySum(int a[], int n){
        
        int cs,ms;
    
        cs = a[0];
        ms = cs;
        
        for(int i=1;i<n;i++){
            if(cs < 0){
                cs = max(cs,a[i]);
            }    
            else{
                cs += a[i];
            }
            
            ms = max(ms,cs);
        }
        
        return ms;
        
    }