Tất cả thử thách
Khó 0 đã giải Tỷ lệ chấp nhận 0%

Minimum Window Substring

Find the shortest piece of text containing all required characters.

Đề bài

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.

Ràng buộc

1 ≤ length of text, pattern ≤ 100,000 (ASCII)

Ví dụ

Ví dụ 1
Đầu vào:
text = "ADOBECODEBANC"
pattern = "ABC"

Kết quả mong đợi:
expected = "BANC"
Đầu vào:
std::string text = "ADOBECODEBANC";
std::string pattern = "ABC";

Kết quả mong đợi:
std::string expected = "BANC";
Đầu vào:
string text = "ADOBECODEBANC";
string pattern = "ABC";

Kết quả mong đợi:
string expected = "BANC";

Giải thích

"BANC" contains A, B and C and nothing shorter does.

Ví dụ 2
Đầu vào:
text = "a"
pattern = "aa"

Kết quả mong đợi:
expected = ""
Đầu vào:
std::string text = "a";
std::string pattern = "aa";

Kết quả mong đợi:
std::string expected = "";
Đầu vào:
string text = "a";
string pattern = "aa";

Kết quả mong đợi:
string expected = "";

Giải thích

Two a's are needed but the text has only one: "".

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.