• Customer Support: admin@thealgorists.com
  • Feedback: We are listening to your every feedback, and taking action to constantly improve your learning experience. If you have any feedback, please use this form: https://thealgorists.com/Feedback.



Problem Statement:


Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.

Example 1:
Input: s = "eceba", k = 2
Output: 3
Explanation: The substring is "ece" with length 3.

Example 2:
Input: s = "aa", k = 1
Output: 2 Explanation: The substring is "aa" with length 2.

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.





The above content is written by:

Abhishek Dey

Abhishek Dey

A Visionary Software Engineer With A Mission To Empower Every Person & Every Organization On The Planet To Achieve More

Microsoft | University of Florida

View LinkedIn profile


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




Subscribe to Our Youtube Channel

Follow Us On LinkedIn
wave