Hidden Substring Segment

Start Timer

0:00:00

Upvote
1
Downvote
Save question
Mark as completed
View comments

Given two strings s and t of lengths m and n respectively, imagine you are scanning through s, a long string of characters, searching for something special. Somewhere inside this string may exist a small, hidden segment that perfectly satisfies a requirement defined by t.

Your task is to return the minimum window substring of s such that every character in t (including duplicates) is included in the window. This window must be continuous, and it must contain all required characters exactly as needed, no more and no less.

If there is no such substring — meaning the required characters cannot all be found together in any part of s — return the empty string "", signaling that the search was unsuccessful.

The testcases will be generated such that the answer is unique, so once the correct window is discovered, there is no doubt that it is the only valid solution.

Example 1:

Input:

s = "INTERVIEWQUERYCODINGQUESTIONS", t = "WING"

Output:

def minWindow(s, t) -> "WQUERYCODING"

Explanation: The minimum window substring "WQUERYCODING" includes 'W', 'I', 'N', and 'G' from string t.

Example 2:

Input:

s = "a", t = "aa"

Output:

def minimum_window_substring(s, t) -> ""

Explanation: Both 'a's from t must be included in the window. Since the largest window of s only has one 'a', return empty string.

Constraints:

  • m == s.length
  • n == t.length
  • 1 <= m, n <= 10^5
  • s and t consist of uppercase and lowercase English letters.
.
.
.
.
.


Comments

Loading comments