कठिन 0 हल किए गए 0% स्वीकृति

Minimum Window Substring

Find the shortest piece of text containing all required characters.

समस्या

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)

उदाहरण

उदाहरण 1
इनपुट:
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.

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

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।