Help Your Friends save 40% on our products


Problem Statement:


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

Example 1:
Input: "eceba"
Output: 3
Explanation: t is "ece" which its length is 3.

Example 2:
Input: "ccaabbb"
Output: 5
Explanation: t is "aabbb" which its length is 5.

Solution:

Prerequisite: Sliding Window

Algorithm:



This is a Premium content.
Please subscribe to the Algorithms course to access the detailed Algorithm discussion.





Java Code:



This is a Premium content.
Please subscribe to Algorithms course to access the code.





Python Code:



This is a Premium content.
Please subscribe to Algorithms course to access the code.





Instructor:



If you have any feedback, please use this form: https://thealgorists.com/Feedback.



Help Your Friends save 40% on our products

wave