← Questions

Shortest substring with N distinct characters

0
MetaCodingLast asked Oct 2025

Given a string and a number n, return the shortest substring that contains n distinct letters (or say that none exists). Use a sliding window that grows until it holds n distinct letters and then shrinks from the left. The round gave about twenty minutes for it.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding