#C4895. Longest Substring with At Most Two Distinct Characters
Longest Substring with At Most Two Distinct Characters
Longest Substring with At Most Two Distinct Characters
Given a string S, find the longest contiguous substring S[i...j] such that the number of distinct characters in it is at most 2. In other words, if we define \( T = \{ S[k] : i \leq k \leq j \} \), then your task is to ensure that \(|T| \le 2\). This problem can be solved efficiently using a sliding window technique.
For example:
Input: abababacccc Output: abababa
inputFormat
The input consists of a single line from standard input containing the string S.
outputFormat
Print to standard output the longest contiguous substring of S that contains at most two distinct characters.
## sampleabbcccdddaaa
cccddd