Question bank › Hashing
Dsa Hashing Medium

Longest Substring with K Unique Characters

Given a string and an integer K, find the length of the longest substring that contains at most K unique characters. Input Format: The first line contains the string. The second line contains the integer K (1 <= K <= length of string). Output Format: Print an integer representing the length of the longest substring. Example: Input: araacek 2 Output: 5

Key concepts

hashingsliding windowsubstrings

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.