Coding Round 1
Senior
programming
Longest Substring with At Most Two Distinct Characters
Given a string s, return the length of the longest substring that contains at most two distinct characters. This problem will test your understanding of the sliding window technique.Function Signature:
Input: s = "eceba"
Output: 3
Explanation: The longest substring is "ece" with length 3.Example 2:
Input: s = "ccaabbb"
Output: 5
Explanation: The longest substring is "aabbb" with length 5.Constraints:
def length_of_longest_substring_two_distinct(s: str) -> int:Example 1: Input: s = "eceba"
Output: 3
Explanation: The longest substring is "ece" with length 3.Example 2:
Input: s = "ccaabbb"
Output: 5
Explanation: The longest substring is "aabbb" with length 5.Constraints:
- 1 <= s.length <= 10^5
- s consists of English letters.
Suggested Answer