Back to course home
0% completed
Vote For New Content
Solution: Gray Code
Problem Statement
Given a positive integer n
, return any valid n-bit
gray code sequence
.
An n-bit
gray code sequence
is a sequence containing integers where:
- Each integer is in the inclusive range [0, 2<sup>n</sup> - 1].
- Sequence always starts with 0.
- All integers are unique in the sequence.
- The
binary representation
ofevery pair
ofadjacent integers
differs
byexactly one bit
. - The
binary representation
of thefirst
andlast
integersdiffers
byexactly one bit
.
Examples
- Example 1
- Input:
n = 4
- Expected Output:
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page