Grokking Google Coding Interview
Ask Author
Back to course home

0% completed

Solution: Gray Code
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

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 of every pair of adjacent integers differs by exactly one bit.
  • The binary representation of the first and last integers differs by exactly one bit.

Examples

  • Example 1
    • Input: n = 4
    • Expected Output:

.....

.....

.....

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