Non Adjacent Ones

No two consecutive positions contain 1s.

Non-Adjacent Ones

Problem Statement

Given a 10-bit binary array, generate an array where no two consecutive positions contain 1s.

This is a classic constraint solving problem often asked in Digital Verification interviews.

Constraints

  • Array size: 10 bits
  • Valid values: 0 or 1

Examples

Example 1:

[1, 0, 1, 0, 1, 0, 0, 0, 0, 0]
Valid
Explanation: No two consecutive 1s

Example 2:

[0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
Valid
Explanation: Alternating 0s and 1s (maximum spacing)

Example 3:

[1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
Invalid
Explanation: Positions 0 and 1 both contain 1s (adjacent)

Example 4:

[0, 0, 1, 0, 1, 0, 0, 1, 0, 0]
Valid
Explanation: All 1s are separated by at least one 0

Example 5:

[0, 0, 0, 0, 0, 0, 0, 1, 0, 1]
Valid
Explanation: 1s at positions 7 and 9 (separated by position 8 which is 0)

Loading the interactive workspace...