Dsa
Sliding Window
Hard
Signal Core Extraction
You are processing a stream of telemetry data represented as a string. Your task is to find the length of the shortest contiguous segment (window) that contains at least K distinct symbols, where each of those K symbols appears at least M times within that segment. If no such segment exists, print 0.
Input Format:
- The first line contains two integers, K and M.
- The second line contains a single string S representing the telemetry data.
Output Format:
- A single integer representing the length of the shortest valid segment.
Example:
Input:
2 2
abaccaba
Output:
4
(Explanation: The segment 'acca' has 2 distinct symbols {'a', 'c'}, and both 'a' and 'c' appear exactly 2 times. Length is 4.)
Key concepts
sliding_windowfrequency_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