Back to Practice
#0217
Diagonal Matrix Pattern
MediumPython25 min20 XP
Problem
Return an n by n grid as a list of strings where both main diagonals are "*" and all other cells are ".".
Why This Matters
Matrix pattern questions build the exact row-column thinking needed for grids, images, and board problems.
Function Signature
def diagonal_pattern(n):
Examples
Example 1
Inputn = 5
Output["*...*", ".*.*.", "..*..", ".*.*.", "*...*"]
Cells on r == c or r + c == n - 1 become stars.
Constraints
- Return the exact requested value.
- Handle small edge cases cleanly.
- Prefer readable Python over clever shortcuts.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputn = 5
Expected["*...*", ".*.*.", "..*..", ".*.*.", "*...*"]
Cells on r == c or r + c == n - 1 become stars.
Hidden Test Categories
small inputlarger inputedge shape