Problems > All Gray Codes

All Gray Codes

Difficulty: 1200 2000 ms 128 MB

bitwise

Print all 2N bit strings of length N in reflected Gray code order (consecutive strings differ in exactly one bit), starting from all zeros.

Input: one integer N.

Output: 2N lines of N-bit strings.

Constraints:

  • 1 ≤ N ≤ 12

Sample Tests

Input 1
2
Output 1
00
01
11
10
Input 2
1
Output 2
0
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.