Reflected Gray Code
Return the standard -bit reflected Gray code: integers starting at 0 where consecutive values (and the last and first) differ in exactly one bit. Use the formula .
Examples
EXAMPLE WALKTHROUGHfour codes
A guided view of the published example, not a trace of your code.
INPUT
[2]TASKreflected_gray_code()
EXPECTED OUTPUT
[0,1,3,2]Start with the input values shown in this example.
Example 1 of 3
Input: n = 2
Output: [0,1,3,2]
Explanation: four codes
Input: n = 1
Output: [0,1]
Explanation: one bit
Input: n = 0
Output: [0]
Explanation: zero bits
Hint 1
XOR each index with itself shifted right by one.