#30Smart Traffic Signal Sequence
A smart traffic controller needs to cycle through 2^n unique signal states. Each state is represented using n binary switches. To ensure smooth transitions, exactly one switch must change between every two consecutive states. The transition from the final state back to the first must also change exactly one switch.
Given an integer n, return any valid sequence of all 2^n signal states satisfying these conditions.
Real-World Applications Error-resistant data transmission Karnaugh maps and digital circuit design Analog-to-digital converters
Examples
Example 1
Input: n = 2
Output: [0, 1, 3, 2]
Explanation: Signal states: 00 → 01 → 11 → 10 Each consecutive state changes exactly one switch.
Example 2
Input: n = 1
Output: [0, 1]
Example 3
Input: n = 3
Output: [0, 1, 3, 2, 6, 7, 5, 4]
