Gray code

Write codeMedium25 min

Your task

An n-bit Gray code sequence is a permutation of the integers 0..2^n-1 that starts at 0 and in which every adjacent pair (including the wrap-around from last to first) differs in exactly one bit. Return the standard reflected Gray code sequence for a given n. n is between 0 and 16.

Examples

gray_code(n: int) -> list[int]
Example 1
Inputgray_code(2)
Output[0, 1, 3, 2]