Longest Substring with At Most K Distinct Characters
Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.
Longest Substring with At Most K Distinct Characters

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
Input
arr ={"s":"eceba","k":2}

Find longest substring with at most 2 distinct characters

e

0

c

1

e

2

b

3

a

4

left=0

right=-1

Character Count Map (k=2)

empty

distinct = 0 k = 2

Window Length:

0

Max Length:

0

Pointers

Valid Window

Invalid Window

Variables
No variables to display
DepthFunction Call
Stack empty
0/6