समस्या
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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।