Longest substring with at most two distinct characters