Programmazione competitivaFacile

Contare stringhe binarie

Guida dettagliata e implementazione Python per il problema "Conteggio stringhe binarie".

Dichiarazione del problema

Facile

Scrivi una funzione count_binary_strings(n) che restituisca il numero di stringhe binarie di lunghezza n che non contengono 1 consecutivi.

Vincoli
  • 1 <= n <= 45

Esempi

Example 1
Input
count_binary_strings(2)
Output
3
Explanation

The valid strings of length 2 are '00', '01', and '10'.

Example 2
Input
count_binary_strings(3)
Output
5
Explanation

The valid strings of length 3 are '000', '001', '010', '100', and '101'.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche della programmazione dinamica 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.