Generate Binary Strings Without Adjacent Zeros - Problem
You are given a positive integer n. A binary string x is valid if all substrings of x of length 2 contain at least one "1".
Return all valid strings with length n, in any order.
In other words, no two consecutive zeros ("00") are allowed in any valid binary string.
Input & Output
Example 1 — Basic Case
$
Input:
n = 3
›
Output:
["010","011","101","110","111"]
💡 Note:
All valid 3-length binary strings without consecutive zeros. Note that "000", "001", and "100" are invalid because they contain "00".
Example 2 — Minimum Size
$
Input:
n = 1
›
Output:
["0","1"]
💡 Note:
For length 1, both "0" and "1" are valid since there are no substrings of length 2 to check.
Example 3 — Small Case
$
Input:
n = 2
›
Output:
["01","10","11"]
💡 Note:
For length 2, "00" is invalid (contains consecutive zeros), but "01", "10", and "11" are all valid.
Constraints
- 1 ≤ n ≤ 20
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code