Given two non-negative integers N and K, return the number of binary strings of length N with at most K consecutive ones
Example:
Input: N = 4, K = 2
Output: 13
Explanation: [
"0000",
"0001",
"0010",
"0011",
"0100",
"0101",
"0110",
"1000",
"1001",
"1010",
"1011",
"1100",
"1101",
]
"0111", "1110" and "1111" are not valid because they have more than 2 consecutive ones
Notes:
K <= N <= 30
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check