pyassistant

Shortest Substring Containing All Distinct Characters

Given a string s, find the shortest substring of s that contains every distinct character that appears in s at least once. If there are multiple shortest substrings, return the one that appears first (smallest starting index). Return the substring itself. The input is a single line containing s (1 <= len(s) <= 10^5).

Example:

Input:
aabcbcdbca
Output:
dbca

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.