150 najlepszych wywiadówŁatwe

Minimalny podciąg okna

Szczegółowy przewodnik i implementacja Python dla problemu „Minimalny podciąg okna”.

Oświadczenie o problemie

Łatwe

Biorąc pod uwagę dwa ciągi s i t o długości odpowiednio m i n, zwróć minimalny podciąg okna s tak, aby każdy znak w t (w tym duplikaty) znalazł się w oknie. Jeśli nie ma takiego podciągu, zwróć pusty ciąg "".

Odpowiedź z pewnością będzie wyjątkowa.

Napisz funkcję minWindow(s: str, t: str) -> str.

Ograniczenia
  • m == len(s), n == len(t)
  • 1 <= m, n <= 10^5
  • s and t consist of uppercase and lowercase English letters

Przykłady

Example 1
Input
s = "ADOBECODEBANC", t = "ABC"
Output
"BANC"
Explanation

The minimum window substring "BANC" (indices 9-12) contains 'A', 'B', and 'C' from t.

Example 2
Input
s = "a", t = "a"
Output
"a"
Explanation

The entire string s is the minimum window.

Example 3
Input
s = "a", t = "aa"
Output
""
Explanation

Both 'a's from t must be included. Since s only has one 'a', return empty string.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla przesuwnego okna, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Otwórz w Edytorze
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.