Back to Practice
#0219

Diamond Star Pattern

MediumPython25 min20 XP

Problem

For n, return a diamond as a list of strings with n rows in the top half and n - 1 rows in the bottom half.

Why This Matters

Diamond patterns train decomposition: solve the top half, then mirror the logic for the bottom half.

Function Signature

def diamond_pattern(n):

Examples

Example 1
Inputn = 3
Output[" *", " ***", "*****", " ***", " *"]

The top grows to width 5, then the bottom shrinks back to width 1.

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 = 3
Expected[" *", " ***", "*****", " ***", " *"]

The top grows to width 5, then the bottom shrinks back to width 1.

Hidden Test Categories
small inputlarger inputedge shape