problem76

package
v1.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 0 Imported by: 0

README

< Previous                  Next >

76. Minimum Window Substring (Hard)

Given two strings s and t, return the minimum window in s which will contain all the characters in t. If there is no such window in s that covers all characters in t, return the empty string "".

Note that If there is such a window, it is guaranteed that there will always be only one unique minimum window in s.

 

Example 1:

Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"

Example 2:

Input: s = "a", t = "a"
Output: "a"

 

Constraints:

  • 1 <= s.length, t.length <= 105
  • s and t consist of English letters.

 

Follow up: Could you find an algorithm that runs in O(n) time?

[Hash Table] [Two Pointers] [String] [Sliding Window]

Similar Questions

  1. Substring with Concatenation of All Words (Hard)
  2. Minimum Size Subarray Sum (Medium)
  3. Sliding Window Maximum (Hard)
  4. Permutation in String (Medium)
  5. Minimum Window Subsequence (Hard)

Hints

Hint 1 Use two pointers to create a window of letters in S, which would have all the characters from T.
Hint 2 Since you have to find the minimum window in S which has all the characters from T, you need to expand and contract the window using the two pointers and keep checking the window for all the characters. This approach is also called Sliding Window Approach.



L ------------------------ R , Suppose this is the window that contains all characters of T 
                          
        L----------------- R , this is the contracted window. We found a smaller window that still contains all the characters in T

When the window is no longer valid, start expanding again using the right pointer. 

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL