Question bank › Sliding Window
Dsa Sliding Window Easy

Max Length of Subarray with K Distinct Characters

Given a string s and an integer k, find the length of the longest substring that contains at most k distinct characters. Input format: - The first line contains an integer k. - The second line contains the string s. Output format: - Print the length of the longest substring with at most k distinct characters. Example: Input: 2 abcabcbb Output: 3

Key concepts

sliding_windowstringsubstring

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.