Le migliori 150 intervisteFacile

Permutazione in stringa

Guida dettagliata e implementazione Python per il problema 'Permutation In String'.

Dichiarazione del problema

Facile

Date due stringhe s1 e s2, restituisce True se s2 contiene una permutazione di s1, o False altrimenti.

In altre parole, restituisce True se una delle permutazioni di s1 è una sottostringa di s2.

Scrivi una funzione checkInclusion(s1: str, s2: str) -> bool.

Vincoli
  • 1 <= len(s1), len(s2) <= 10^4
  • s1 and s2 consist of lowercase English letters

Esempi

Example 1
Input
s1 = "ab", s2 = "eidbaooo"
Output
True
Explanation

s2 contains one permutation of s1: "ba" (starting at index 3).

Example 2
Input
s1 = "ab", s2 = "eidboaoo"
Output
False
Explanation

No permutation of "ab" exists as a contiguous substring in s2.

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.