Le migliori 150 intervisteFacile

Sottostringa finestra minima

Guida dettagliata e implementazione Python per il problema della "sottostringa finestra minima".

Dichiarazione del problema

Facile

Date due stringhe s e t di lunghezza m e n rispettivamente, restituisce la sottostringa minima della finestra di s in modo tale che ogni carattere in t (inclusi i duplicati) sia incluso nella finestra. Se non esiste una sottostringa di questo tipo, restituisce la stringa vuota "".

La risposta è garantita per essere unica.

Scrivi una funzione minWindow(s: str, t: str) -> str.

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

Esempi

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?
Prendi in considerazione l'utilizzo di strutture dati specifiche della finestra scorrevole come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

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

Apri nell'editor
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

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.