Have a doubt in the fastest solution


#1

Can someone explain why the condition : sumTillNow==maxTillNow && end - start +1 < ansLength shouldn’t be sumTillNow==maxTillNow && end - start +1 > ansLength
vector Solution::maxset(vector &A) {
long long int start=0, end=0, ansStart=0, length=0, ansLength=0, ansEnd=-1, sumTillNow = INT_MIN, maxTillNow=INT_MIN;
int i=0;

while(i<A.size()){
if(A[i]>=0){
start = i;// Start of the subarray
sumTillNow =0;
length =0;

        while(A[i]>=0 && i<A.size()){
            sumTillNow +=A[i];
            i++;   
        }
        end = i-1;
        
       if( ( sumTillNow>maxTillNow ) || ( sumTillNow==maxTillNow && end - start +1 < ansLength   **/*confused about this condition*/**       ) ){
           ansStart = start;
           ansEnd = end;
           ansLength = start + end -1;
           maxTillNow = sumTillNow;
        }
   }
   i++;
   
}
   //Understood
   vector <int> ans;
   for(int i=ansStart; i<=ansEnd;i++){
       ans.push_back(A[i]);
   }
   
   return ans;

}