Le migliori 150 intervisteMedio

Stringa di interlacciamento

Guida dettagliata e implementazione Python per il problema 'Interleaving String'.

Dichiarazione del problema

Medio

Date le stringhe s1, s2 e s3, determinare se s3 è formata da un interlacciamento di s1 e s2.

Un interlacciamento di due stringhe s e t è una configurazione in cui sono divise in sottostringhe non vuote tali che s = s1 + s2 + ... + sn, t = t1 + t2 + ... + tm, |n - m| <= 1 e la stringa interlacciata è s1 + t1 + s2 + t2 + ... o t1 + s1 + t2 + s2 + ...

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

Vincoli
  • 0 <= len(s1), len(s2) <= 100
  • 0 <= len(s3) <= 200
  • s1, s2, and s3 consist of lowercase English letters

Esempi

Example 1
Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
Output
True
Explanation

aadbbcbcac can be formed by interleaving "aabcc" and "dbbca".

Example 2
Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
Output
False
Explanation

It is impossible to interleave s1 and s2 to obtain s3.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche per DP 2D 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.