A Gray code is a sequence of all 2^n numbers from 0 to 2^n - 1 where each number differs from the next in exactly one bit, and the last differs from the first in one bit too. Return the standard (reflected) Gray code that starts at 0.
For n = 2: [0, 1, 3, 2] (binary 00, 01, 11, 10).
Example 1
Input:
gray_code(2)
Output:
[0, 1, 3, 2]
Example 2
Input:
gray_code(0)
Output:
[0]
0 <= n <= 16No results yet
Run your code to check it against the examples, or submit to run every test.