VOOZH about

URL: https://www.geeksforgeeks.org/dsa/hollow-diamond-pattern/

⇱ Hollow Diamond Pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Hollow Diamond Pattern

Last Updated : 11 Mar, 2026

Given an integer N, print the pattern shown below.

Examples:

Input: N=5

Output:

👁 star-pattern

Input: N=3

Output:

👁 Screenshot-2026-03-10-181656

Using Nested Loops - O(n^2) Time and O(1) Space

  • Iterate through 2 × n − 1 rows to form the upper and lower parts of the pattern, and compute a variable (comp) to control the spacing for each row.
  • Print leading spaces using an inner loop so that the stars shift toward the center and form the desired shape.
  • Use another inner loop to print stars at the first and last positions of the row and spaces in between, creating a hollow pattern.

Output
 * 
 * * 
 * * 
 * * 
 * 
Comment
Article Tags: