Question bank › Strings
Dsa Strings Medium

Shortest Frequency Window

Find the length of the shortest substring that contains at least K different characters, where each of those characters must appear at least 2 times within that substring. If no such substring exists, print -1. Example: Input: 2 aabbcc Output: 4 (Explanation: 'aabb' has K=2 characters ('a', 'b'), and each appears twice. Length 4. 'bbcc' also works.)

Key concepts

sliding-windowhashmap

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.