public int solution(final int[] sizes, final int[] directions) {
            final Deque<Fish> stack = new LinkedList<Fish>();

            final int N = sizes.length;
            for (int i = 0; i < N; i++) {
                final Fish downstreamFish = new Fish(sizes[i], directions[i]);

                while (!stack.isEmpty()) {
                    final Fish upstreamFish = stack.peek();
                    if (upstreamFish.direction == DOWNSTREAM && downstreamFish.direction == UPSTREAM) {
                        if (upstreamFish.size < downstreamFish.size) {
                            stack.pop(); // Upstream fish eaten.
                        } else if (upstreamFish.size == downstreamFish.size) {
                            stack.push(downstreamFish);
                            break;
                        }
                        else {
                            break; // Downstream fish eaten.
                        }
                    }
                    else { // Fish can never meet.
                        stack.push(downstreamFish);
                        break;
                    }
                }

                if (stack.isEmpty()) {
                    stack.push(downstreamFish);
                }
            }

            return stack.size();
        }