#384 Minimum Substring Containing All Characters
Write a function that accepts two strings, a text and an alphabet, and returns the shortest substring of the text that contains every character from the alphabet at least once, while possibly containing other characters as well. If several matching substrings have the same length, return the one closest to the beginning of the text.
The second string is guaranteed to be non-empty and to contain only unique characters.
Examples:
searchPangram("abacaba", "bc") == "bac" <- choose the leftmost of the equal-length substrings 'bac' and 'cab'
searchPangram("bacb", "bc") == "cb"
abbc ac => abbc
searchPangram("abacaba", "bcd") == ""
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor