Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Gray Code

Print an n-bit Gray code sequence as integers: it starts at 0, has 2^n values, consecutive values differ in exactly one bit, and (for this problem) is the standard reflected sequence i XOR (i >> 1).

Constraints

1 <= n <= 16

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.