Longest Substring with Two Distinct Characters
Find the longest substring with at most two distinct characters.
Input: s = "ccaabbb"
Output: 5
Explanation: The substring "aabbb" contains exactly two distinct characters and has a maximum length of 5.
Find the longest substring with at most two distinct characters.
Input: s = "ccaabbb"
Output: 5
Explanation: The substring "aabbb" contains exactly two distinct characters and has a maximum length of 5.
More interviews, more skills, more success.
Be the first to share your approach to this question
2 answers published. Last candidate submission on Sep 7 2026, 2:02pm PDT. Interview question asked to Software Engineers interviewing at Taiwan Semiconductor, Unacademy, GameStop and other companies. Original question asked: Longest Substring with Two Distinct Characters. Question last reported by a candidate interviewing at Better.com for a Software Engineer interview on Oct 6 2026, 2:35am PDT.