Start learning free

LESSON 319 OF 349 · DYNAMIC PROGRAMMING

Binary Strings Without Consecutive Ones in Swift

Practice O(n)

Given a non-negative integer N return the number of binary strings of length N without 2 consecutive ones

Example:

Input: N = 3
Output: 5
Explanation: [
    "000",
    "001",
    "010",
    "100",
    "101",
]
Notes: N <= 30
STEP 1 OF 5
    Ctrl + Enter to check

    Binary Strings Without Consecutive Ones in Swift

    Keep going with SwiftAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free