CSES Problemset/Introductory Problems
Gray Code
#2205Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude DesktopA Gray code is a list of all bit strings of length , where any two successive strings differ in exactly one bit (i.e., their Hamming distance is one).
Your task is to create a Gray code for a given length .
Input
The only input line has an integer .
Output
Print lines that describe the Gray code. You can print any valid solution.
Constraints
Sample Test Cases (1)
Example 1ID: sample-1
Input
2
Expected Output
00 01 11 10
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 charsTest Bench
Input (stdin)
2
Expected Output
00 01 11 10