Given an integer bit_length, generate a sequence of 2^bit_length integers such that: (1) Each integer is in the range [0, 2^bit_length - 1]. (2) The first integer is 0. (3) Each integer appears exactly once. (4) The binary representation of every pair of adjacent integers differs by exactly one bit. (5) The binary representation of the first and last integers differs by exactly one bit. Return any valid sequence meeting these criteria.
Example 1
Input: 2
Output: [0, 1, 3, 2]
Explanation: Binary representations: [00, 01, 11, 10]. Each adjacent pair differs by one bit, and the sequence wraps around.
Example 2
Input: 3
Output: [0, 1, 3, 2, 6, 7, 5, 4]
Explanation: Binary representations: [000, 001, 011, 010, 110, 111, 101, 100]. Each adjacent pair differs by one bit, and the sequence wraps around.
Constraints
Case 1
Input: 4
Expected: [0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8]
Case 2
Input: 1
Expected: [0, 1]
Case 3
Input: 5
Expected: [0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 24, 25, 27, 26, 30, 31, 29, 28, 20, 21, 23, 22, 18, 19, 17, 16]