Problème
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.
Contraintes
1 ≤ length of text, pattern ≤ 100,000 (ASCII)
Exemples
Entrée :
text = "ADOBECODEBANC"
pattern = "ABC"
Sortie attendue :
expected = "BANC"
Entrée :
std::string text = "ADOBECODEBANC";
std::string pattern = "ABC";
Sortie attendue :
std::string expected = "BANC";
Entrée :
string text = "ADOBECODEBANC";
string pattern = "ABC";
Sortie attendue :
string expected = "BANC";
Explication
"BANC" contains A, B and C and nothing shorter does.
Entrée :
text = "a"
pattern = "aa"
Sortie attendue :
expected = ""
Entrée :
std::string text = "a";
std::string pattern = "aa";
Sortie attendue :
std::string expected = "";
Entrée :
string text = "a";
string pattern = "aa";
Sortie attendue :
string expected = "";
Explication
Two a's are needed but the text has only one: "".
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.