Smallest Substring with All Unique Characters

Hard
string sliding-window hash-map two-pointers
Problem Description

Find the smallest substring that contains all unique characters present in the input string. This is a variation of the minimum window substring problem where the window must contain all distinct characters from the original string.

Input Format
A single string containing lowercase letters.
Output Format
The smallest substring containing all unique characters. If multiple substrings have the same minimum length, return the first one found.
Constraints
• 1 ≤ string length ≤ 10^5
• String contains only lowercase English letters
• At least one character in the string
• Return the lexicographically first substring if multiple solutions exist
Sample Input/Output
Input:
aabcbcdbca
Output:
dbca
Explanation

The string contains unique characters: a, b, c, d. The smallest substring containing all these characters is "dbca" (length 4). Other valid substrings like "abcbcd" are longer.

Solution Hints
120
Points
3000ms
Time Limit
256MB
Memory Limit
Code Editor
Register to Submit
Register to Access Code Editor

Create a free account to solve coding problems and track your progress.

Register Now
Feedback