Given an integer bit_count, generate a sequence of 2^bit_count integers such that: 1) Each integer is in the range [0, 2^bit_count - 1]. 2) The sequence starts with 0. 3) Each integer appears only 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 requirements.
Example 1
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 first and last also differ by one bit.
Example 2
Input: 4
Output: [0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8]
Explanation: Binary representations: [0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, 1000].
Constraints
Case 1
Input: 2
Expected: [0, 1, 3, 2]
Case 2
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]