title: Python codility lesson : stacks and queues fish bug
body: <p>My code seems to be returning the wrong answer for one test case on codility.(rest of the test cases are correct)</p>
  
  <p>for a test case:
  large_random</p>
  
  <p>large random test, N = ~100,000
  i'm getting a </p>
  
  <p>got 868 expected 840</p>
  
  <p>question link:
  <a href="https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/" rel="nofollow noreferrer">https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/</a></p>
  
  <p><pre><code></p>
  
  <p>def solution(A, B):
      #declare stacks for fish traveling downstrea, upstream
      dstrm = []
      ustrm = []
      #set counter to zero for fish traveling upstream UNHINDERED
      #by fish traveling downstream, needed because iteration starts upstream
      counter = 0
      n = len(A)
      #iterate over input, starting from upstream
      for i in range(n):
          if B[i] == 0:
              ustrm.append(A[i])
          elif B[i] == 1:
              dstrm.append(A[i])</p>
  
  # clear upstream stack of fish known to be UNHINDERED, increase counter
          if len(ustrm) &gt; 0 and len(dstrm) == 0:
              counter += len(ustrm)
              ustrm.clear()
  
      #compare what's bigger and decrease stack of fish that is eaten
  
          while len(dstrm) &gt; 0 and len(ustrm) &gt; 0:
              if dstrm[-1] &gt; ustrm[-1]:
                  ustrm.pop()
              elif ustrm[-1] &gt; dstrm[-1]:
                  dstrm.pop()
  
      return len(dstrm) + len(ustrm) + counter
  </code></pre>
  
  <p></p>