title: Find out the maximum sub-array of non negative numbers from an array
body: <p><code>A : [1, 2, 5, -7, 2, 3]</code> The two sub-arrays are <code>[1, 2, 5]</code> <code>[2, 3]</code>. 
  The answer is <code>[1, 2, 5]</code>as its sum is larger than <code>[2, 3]</code></p>
  
  <p>NOTE: If there is a tie, then compare with segment's length and return segment which has maximum length.<br>
  NOTE 2: If there is still a tie, then return the segment with minimum starting index.</p>
  
  <p>I have written the code and its working for some cases but not for this one :</p>
  
  <pre><code>A : [ 1967513926, 1540383426, -1303455736, -521595368 ]
  Your function returned the following :
  1967513926 
  The expected returned value :
  1967513926 1540383426 
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><code>int* maxset(int* A, int n1, int *length_of_array) {
  
       int greatin=0,greatout=0,greatin1=0,number1=0,number=0;
       int n3,i,count=0,k,sum=0,max=0,ini=0,end=0;
  
       for(i=0;i&lt;n1;i++)
       {
           ini=end;
           if(A[i]&gt;=0)
           {
               count=1;
               number++;
               sum=sum+A[i];
               if (sum&gt;max )
               {
  
                   max=sum;
                   greatout=i;
                   greatin=ini;
  
               }
               else if (sum==max &amp;&amp; number&gt;number1)
               {
                    max=sum;
                   greatout=i;
                   greatin=ini;
               }
           }
          else
          {
              sum=0;
              end=i+1;
              number1=number;
              number=0;
  
          }
       }
      if(count&gt;0)
      {
            count=0;
            n3=greatout-greatin+1;
            *length_of_array=n3;
            int * ret = (int *) malloc(sizeof(int) * *length_of_array);
  
            for(i=greatin;count&lt;n3;i++)
            {
                 ret[count]=A[i];
                 count++;
  
            } 
       return ret;
  
      }
      else
       {
  
        *length_of_array=0;
        int * ret = (int *) malloc(sizeof(int) * *length_of_array);
        return ret;
       }
  }
  </code></pre>