Условие
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.
Ограничения
1 ≤ length of text, pattern ≤ 100,000 (ASCII)
Примеры
Ввод:
text = "ADOBECODEBANC"
pattern = "ABC"
Ожидаемый вывод:
expected = "BANC"
Ввод:
std::string text = "ADOBECODEBANC";
std::string pattern = "ABC";
Ожидаемый вывод:
std::string expected = "BANC";
Ввод:
string text = "ADOBECODEBANC";
string pattern = "ABC";
Ожидаемый вывод:
string expected = "BANC";
Пояснение
"BANC" contains A, B and C and nothing shorter does.
Ввод:
text = "a"
pattern = "aa"
Ожидаемый вывод:
expected = ""
Ввод:
std::string text = "a";
std::string pattern = "aa";
Ожидаемый вывод:
std::string expected = "";
Ввод:
string text = "a";
string pattern = "aa";
Ожидаемый вывод:
string expected = "";
Пояснение
Two a's are needed but the text has only one: "".
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.