title: How to make the run time of the program to ϴ n
body: <p>The requirement is that the input will be set of integer ranging from -5 to 5, the result should give the longest subset of the integer, in which the total must be greater or equal to zero.</p>
  
  <p>I can only come up with the following:
  The input will be input[0 to n]</p>
  
  <pre><code>let start, longestStart, end, longestEnd, sum = 0
  
  for i=0 to n-1
  start = i
  sum = input[i]
    for j=1 to n
    if sum + input[j] &gt;= 0 then 
      end=j;
    if end - start &gt; longestEnd - longestStart then
      longestStart = start;
      longestEnd = end;
  </code></pre>
  
  <p>However this is ϴ(n^2). I would like to know what are the ways to make this loop become ϴ(n)
  Thank you</p>