Smallest Complete Label Strip
Preview mode. Log in to edit, run, submit, and save progress.
Medium
Smallest Complete Label Strip
A printer produced one long strip of lowercase labels. You want to cut out the shortest continuous piece that still contains every different label type that appears anywhere on the full strip. Return the length of that shortest piece.
Examples
Example 1
Input:
aabcbcdbca
Output:
4
Explanation: The substring dbca contains all distinct characters.
Approach hint
First count how many distinct characters exist in the whole string.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
solution.cpp