Tap here to switch tabs
Problem
Submissions

Problem: Longest Substring with At Most K Distinct Characters

med
30 min
Try to solve the Longest Substring with At Most K Distinct Characters problem.

Statement

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

Constraints:

  • 1≤1 \leq s.length ≤5⋅104\leq 5 \cdot 10^4

  • 0≤0 \leq k ≤50\leq 50

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Substring with At Most K Distinct Characters

med
30 min
Try to solve the Longest Substring with At Most K Distinct Characters problem.

Statement

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

Constraints:

  • 1≤1 \leq s.length ≤5⋅104\leq 5 \cdot 10^4

  • 0≤0 \leq k ≤50\leq 50