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

For example, Given s = `"eceba"`

, `k = 3`

,

T is `"eceb"`

which its length is `4`

.

solution

Skip to content
# Longest Substring with At Most K Distinct Characters

Category: two pointer

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

For example, Given s = `"eceba"`

, `k = 3`

,

T is `"eceb"`

which its length is `4`

.

solution