Programowanie konkurencyjneŁatwe

Policz ciągi binarne

Szczegółowy przewodnik i implementacja Python dla problemu „Count Binary Strings”.

Oświadczenie o problemie

Łatwe

Napisz funkcję count_binary_strings(n), która zwraca liczbę ciągów binarnych o długości n, które nie zawierają kolejnych jedynek.

Ograniczenia
  • 1 <= n <= 45

Przykłady

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?
Rozważ użycie struktur danych specyficznych dla programowania dynamicznego, 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.