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 representationofevery pairofadjacent integersdiffersbyexactly one bit. - The
binary representationof thefirstandlastintegersdiffersbyexactly one bit.
Examples
- Example 1
- Input:
n = 4 - Expected Output:
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible