class PrimitiveArrays {

    public static long[] intersect( long[] left, long[] right )
    {
        if ( left == null || right == null )
        {
            return EMPTY_LONG_ARRAY;
        }

        assert isSortedSet( left ) && isSortedSet( right );

        long uniqueCounts = countUnique( left, right );
        if ( uniqueCounts == 0 ) // complete intersection
        {
            return right;
        }
        if ( right( uniqueCounts ) == right.length || left( uniqueCounts ) == left.length ) // non-intersecting
        {
            return EMPTY_LONG_ARRAY;
        }

        long[] intersect = new long[left.length - left( uniqueCounts )];

        int cursor = 0;
        int l = 0;
        int r = 0;
        while ( l < left.length && r < right.length )
        {
            if ( left[l] == right[r] )
            {
                intersect[cursor++] = left[l];
                l++;
                r++;
            }
            else if ( left[l] < right[r] )
            {
                l++;
            }
            else
            {
                r++;
            }
        }

        assert cursor == intersect.length;
        return intersect;
    }

    private  PrimitiveArrays();

}