Tap here to switch tabs
Problem
Ask
Submissions

Problem: Minimum Window Subsequence

hard
40 min
Explore how to find the shortest substring of one string that contains another as a subsequence using sliding window strategies. Learn to identify minimal contiguous sequences where the order of characters in the subsequence is preserved, enhancing problem-solving skills in string manipulation and efficient searching.

Statement

Given two strings, s1 and s2, find and return the shortest substring of s1 in which all the characters of s2 appear in the same order, but not necessarily next to each other (i.e., s2 should be a subsequence of the substring).

If no such substring exists, return an empty string "". If there are multiple shortest substrings, return the one that appears first in s1 (i.e., with the left-most starting index).

Note:substring is a contiguous sequence of characters within a string. A subsequence is a sequence of characters that can be derived from a string by deleting some characters without changing the order of the remaining characters. For example, “edu” is a substring and “cave” is a subsequence of “educative.”

Constraints:

  • 11 \leq s1.length 2×103\leq 2 \times 10^{3}

  • 11 \leq s2.length 100\leq 100

  • s1 and s2 consist of uppercase and lowercase English letters.

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Minimum Window Subsequence

hard
40 min
Explore how to find the shortest substring of one string that contains another as a subsequence using sliding window strategies. Learn to identify minimal contiguous sequences where the order of characters in the subsequence is preserved, enhancing problem-solving skills in string manipulation and efficient searching.

Statement

Given two strings, s1 and s2, find and return the shortest substring of s1 in which all the characters of s2 appear in the same order, but not necessarily next to each other (i.e., s2 should be a subsequence of the substring).

If no such substring exists, return an empty string "". If there are multiple shortest substrings, return the one that appears first in s1 (i.e., with the left-most starting index).

Note:substring is a contiguous sequence of characters within a string. A subsequence is a sequence of characters that can be derived from a string by deleting some characters without changing the order of the remaining characters. For example, “edu” is a substring and “cave” is a subsequence of “educative.”

Constraints:

  • 11 \leq s1.length 2×103\leq 2 \times 10^{3}

  • 11 \leq s2.length 100\leq 100

  • s1 and s2 consist of uppercase and lowercase English letters.