Question bank › Sliding Window
Dsa Sliding Window Medium

Maximum Distinct Substring

Given a string s, find the length of the longest substring that contains at most k distinct characters. If k is 0 or greater than the length of the string, return 0. Example: Input: "abcba", 2 Output: 3 (Note: The longest substring with at most 2 distinct characters is "bcb".)

Key concepts

sliding_windowsubstringhash_map

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.