Generate All Nonconsecutive Binary Strings

Published by Mubashir Hassan in

Create a function to generate all nonconsecutive binary strings where nonconsecutive is defined as a string where no consecutive ones are present, and where n governs the length of each binary string.

Examples

generateNonconsecutive(1) ➞ "0 1"

generateNonconsecutive(2) ➞ "00 01 10"

generateNonconsecutive(3) ➞ "000 001 010 100 101"

generateNonconsecutive(4) ➞ "0000 0001 0010 0100 0101 1000 1001 1010"

Notes

N/A

Watch a quick demo on how Edabit works.