Build an 8x8 NumPy Checkerboard by Tiling a 2x2 Block With np.tile
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Write a function `checkerboard()` that returns an 8x8 checkerboard of 0s and 1s. Build it by tiling the 2x2 base block `[[0, 1], [1, 0]]` with `np.tile`. Do not use index slicing or element assignment.
The result must be an integer array of shape `(8, 8)` that alternates between 0 and 1 along every row and every column, with `[0][0] == 0`.
```python
checkerboard()
# array([[0, 1, 0, 1, 0, 1, 0, 1],
# [1, 0, 1, 0, 1, 0, 1, 0],
# ...
# [1, 0, 1, 0, 1, 0, 1, 0]])
# shape (8, 8), corner [0][0] == 0
```
```hint Where the copies meet
Look at how `np.tile` reads a tuple `reps` for a 2-D input, then check that the pattern keeps alternating across the edge where one copy of the block meets the next.
```
### What a Strong Answer Covers
- Why `[[0, 1], [1, 0]]` is one full period of the checkerboard along both axes, so neighboring copies join without breaking the alternation.
- The `reps` value passed to `np.tile` and how it determines the `(8, 8)` shape.
- The dtype of the result and why the corner is 0.
- What `np.tile` allocates and what the call costs.
### Follow-up Questions
- How would you generalize the function to an `n x n` board, including odd `n`?
- How does `np.tile` differ from a broadcasting approach for this pattern?
Overview: Write a NumPy function that builds an 8x8 checkerboard of 0s and 1s by tiling a 2x2 block with np.tile, without slicing or element assignment. It tests how the reps argument sets the output shape, why neighboring copies keep the pattern, and how to extend the idea to any board size.