LC: 727. Minimum Window Subsequence
https://leetcode.com/problems/minimum-window-subsequence/
727. Minimum Window Subsequence
Given strings s1 and s2, return the minimum contiguous substring part of s1, so that s2 is a subsequence of the part.
If there is no such window in s1 that covers all characters in s2, return the empty string "". If there are multiple such minimum-length windows, return the one with the left-most starting index.
Example 1:
Input: s1 = "abcdebdde", s2 = "bde"
Output: "bcde"
Explanation:
"bcde" is the answer because it occurs before "bdde" which has the same length.
"deb" is not a smaller window because the elements of s2 in the window must occur in order.Example 2:
Input: s1 = "jmeqksfrsdcmsiwvaovztaqenprpvnbstl", s2 = "u"
Output: ""Constraints:
1 <= s1.length <= 2 * 1041 <= s2.length <= 100s1ands2consist of lowercase English letters.
727. Minimum Window Subsequence:
The Essence:
Wir sollen den Suchraum so viel wie möglich enger machen. Zuerst findet man ein Intervall, in dem das erste und das letzte Zeichen liegen. Dann sucht mann umgekehrt die Indizes der vorherigen Zeichen von dem Ende dieses Intervalls. Damit findet man das kleinstmögliche Intervall für die Teilzeichenfolge.
Details:
In unserem PR können die Problemlöser die ausführlichen Erläuterungen der Lösungen, eine mit dynamischer Programmierung, und den Code finden.
Solutions:
Default Code:
Last updated