Problem
Find the shortest contiguous substring of text that contains every character of pattern, including repeats. If several are equally short, return the leftmost.
Implement min_window(text, pattern).
Input
text: The text to search. pattern: The characters that must appear.
Output
Return the shortest window, or an empty string if none exists.
Einschränkungen
1 ≤ length of text, pattern ≤ 100,000 (ASCII)
Beispiele
Eingabe:
text = "ADOBECODEBANC"
pattern = "ABC"
Erwartete Ausgabe:
expected = "BANC"
Eingabe:
std::string text = "ADOBECODEBANC";
std::string pattern = "ABC";
Erwartete Ausgabe:
std::string expected = "BANC";
Eingabe:
string text = "ADOBECODEBANC";
string pattern = "ABC";
Erwartete Ausgabe:
string expected = "BANC";
Erläuterung
"BANC" contains A, B and C and nothing shorter does.
Eingabe:
text = "a"
pattern = "aa"
Erwartete Ausgabe:
expected = ""
Eingabe:
std::string text = "a";
std::string pattern = "aa";
Erwartete Ausgabe:
std::string expected = "";
Eingabe:
string text = "a";
string pattern = "aa";
Erwartete Ausgabe:
string expected = "";
Erläuterung
Two a's are needed but the text has only one: "".
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.