9.1.6 Checkerboard V1 Codehs May 2026
9.1.6 Checkerboard v1
The goal of the exercise in CodeHS is to create a 2D array representing an
# Initialize the board board = []
- We evaluate each of n^2 cells once → O(n^2) time.
- Building each line of length n costs O(n), total output size O(n^2).
- Memory overhead minimal: one line buffer of length O(n) or direct streaming.
- Base: For n = 0, produce no lines (acceptable empty board). For n = 1, r = c = 0 → (0+0)%2 = 0 → a placed, matches specification.
- Inductive (structure): Assume row r and column c follow rule; neighbor at (r, c+1) has parity (r + c + 1) which flips parity, so token differs. Similarly for vertical neighbor (r+1, c). Therefore adjacency alternation guaranteed across whole grid.
- Termination: loops run finite iterations proportional to n^2.
Common Mistakes and How to Avoid Them
for(int col = 0; col < size; col++)
Alternating Pattern:
Use the modulus operator (%) to create the "every other" effect. A reliable trick is checking if (i + j) % 2 == 0 . 9.1.6 checkerboard v1 codehs
for row in board: print(" ".join(row))