Simulation I: The Complete Set
Challenge on lesson: Simulation I — The Complete Set
CHALLENGE
Difficulty: advanced+25 XP
**Task.** A string of n lowercase letters; the alphabet is exactly the k distinct letters that appear (given as k). Find the length of the shortest contiguous substring containing all k distinct letters at least once each. Print that length, or −1 if impossible. **Constraints:** 1 ≤ n ≤ 200000; 1 ≤ k ≤ 26 (with k = number of distinct letters in the string, so −1 cannot actually occur — decide for yourself whether to trust that).
Press Submit to check your solution.
Back to lesson: Simulation I — The Complete Set