#K75477. Longest Substring with Two Distinct Characters
Longest Substring with Two Distinct Characters
Longest Substring with Two Distinct Characters
Given a string s, your task is to find the longest contiguous substring that contains exactly two distinct characters.
The solution must be implemented using a sliding window technique. In case of multiple substrings of maximum length, the function should return the one that appears first.
For example, when s = "eceba", the longest substring with exactly two distinct characters is "ece".
All input will be provided through standard input (stdin
) and the answer should be output through standard output (stdout
).
inputFormat
The input consists of a single line containing a non-empty string s (which might also be empty in some cases). The string contains only ASCII characters.
outputFormat
Output the longest contiguous substring of s that contains exactly two distinct characters. If the input string is empty, output an empty string.
## sampleeceba
ece