
Minimum Window Substring

Given a string line
and a pattern pattern
, write a function to find the minimum window substring of the line
that contains at least all the characters of the pattern
(may contain other characters also). The order of the characters in the line/pattern
doesn't matter, but the letter case does.
Your function should return a tuple of starting and ending indexes of line
which form the needed window (right border is excluded). If there is no such substring in line
to match pattern
, return (-1, -1)
.
Input: Two strings (str).
Output: Tuple of two integers (int).
Examples:
assert window("ADOBECODEBANC", "ABC") == (9, 13) assert window("ab", "a") == (0, 1) assert window("ab", "A") == (-1, -1) assert window("abcdef", "ace") == (0, 5)
Precondition:
- all letters in pattern are unique.