less than 1 minute read

Given a string s, find the length of the longest substring that contains at most 2 distinct characters.

Constraints

  • n ≤ 10,000 where n is the length of s.

https://binarysearch.com/problems/Longest-Substring-with-2-Distinct-Characters

Examples

Example 1

Input

  • s = abccb

Output

  • answer = 4

Explanation

"bccb" is the longest substring with at most 2 distinct characters.

Solution

Leave a comment