Codility voracious fish are moving along a river
This is an example of a situation where good naming is your friend. Instead of parameters A and B, and magic numbers 0 and 1, and the rather long-winded expression stack.Peek(), I suggest you start by installing some useful names:

const int UPSTREAM = 0;
const int DOWNSTREAM = 1;

public static int solution(int[] size, int[] direction)
{
    var stack = new Stack&lt;int&gt;();
    var updateStack = false;
    for (int i = 0; i &lt; size.Length; i++)
    {
        if (stack.Count &lt;= 0) //initial data
            stack.Push(i);
        else
        {
            var lastFish = stack.Peek();

            if (direction[i] == direction[lastFish] 
             || direction[i] != direction[lastFish] 
                &amp;&amp; direction[lastFish] == UPSTREAM 
                &amp;&amp; direction[i] == DOWNSTREAM) 
            {
                stack.Push(i);
            }
            else
            {
                while (stack.Count &gt; 0 
                       &amp;&amp; size[lastFish] &lt; size[i] 
                       &amp;&amp; direction[lastFish] == DOWNSTREAM 
                       &amp;&amp; direction[i] == UPSTREAM)
                {
                    updateStack = true;
                    stack.Pop();
                    lastFish = stack.Peek();
                }
                if (updateStack)
                    stack.Push(i);
            }
        }

    }
    return stack.Count;
}


This shows me there is some confusion on your part. You are allowed to assume that a logical or (||) fails because it's false - there's no need to repeat the test in a false mode:

if (direction[i] == direction[lastFish] 
 || direction[i] != direction[lastFish] &amp;&amp; ...


Instead, just assume that failure implies failure, and go on:

if (direction[i] == direction[lastFish] 
  || direction[lastFish] == UPSTREAM 
     &amp;&amp; direction[i] == DOWNSTREAM) 


Furthermore, you can assume that since you know the directions are different, and since you know there are only two directions, testing one of them is enough:

if (direction[i] == direction[lastFish] || direction[i] == DOWNSTREAM)


That said, I notice that you initialize updateStack to false outside of your loop and never reset it to false anyplace else. This means that once you've set updateStack = true, it will stay true forever (inside you loop, anyway). That's probably the source of your error, because it should stop being true once you've updated the stack.