Grokking Google Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Gray Code (medium)
On this page

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!

On this page