Given two strings, source
and target
, find the smallest substring in source
that includes every character from target
at least once. The solution should have a time complexity of O(n).
Example 1: sourceStr = "ZXAYBCYABZ" targetStr = "ABC" Expected result: "AYBC" Example 2: sourceStr = "HELLOWORLD" targetStr = "LOD" Expected result: "LOWORL" Example 3: sourceStr = "AABBCCDD" targetStr = "BCD" Expected result: "BCCDD" Example 4: sourceStr = "XYZ" targetStr = "ABC" Expected result: ""
source
≤ 15,000target
≤ 10,000source
and target
consist of uppercase English letters.