educative.io

Educative

I did not understand the question

Hi, the example below says: no more than 2 distinct character. However, I see one substring with “a” character three times. if the limit is 2, the result should be “raa”. I tried to understand this question, but nothing til now.

Input: String="araaci", K=2
Output: 4
Explanation: The longest substring with no more than '2' distinct characters is "araa".

Hey @Cleison_Melo,

The question mentions " Given a string, find the length of the longest substring in it with no more than K distinct characters." I think you missed this term Distinct when you were reading the question, since “araa” is the longest sting with only 2 distinct characters (“a” and “r”) it is the right solution to this problem.

Hope this makes the question clearer.

Thanks