Problema
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.
Restricciones
1 ≤ length of text, pattern ≤ 100,000 (ASCII)
Ejemplos
Entrada:
text = "ADOBECODEBANC"
pattern = "ABC"
Salida esperada:
expected = "BANC"
Entrada:
std::string text = "ADOBECODEBANC";
std::string pattern = "ABC";
Salida esperada:
std::string expected = "BANC";
Entrada:
string text = "ADOBECODEBANC";
string pattern = "ABC";
Salida esperada:
string expected = "BANC";
Explicación
"BANC" contains A, B and C and nothing shorter does.
Entrada:
text = "a"
pattern = "aa"
Salida esperada:
expected = ""
Entrada:
std::string text = "a";
std::string pattern = "aa";
Salida esperada:
std::string expected = "";
Entrada:
string text = "a";
string pattern = "aa";
Salida esperada:
string expected = "";
Explicación
Two a's are needed but the text has only one: "".
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.