Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Print Diamond Pattern

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Print Diamond Pattern. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a positive integer n, print a centered diamond pattern of height 2n - 1 using the * character. The widest row must contain 2n - 1 stars, and each row should be padded with spaces so the diamond is symmetric. Return the pattern as an array of strings, where each string represents one row.

Constraints

  • 1 <= n <= 100
  • Each row contains only spaces and '*'
  • Output height is exactly 2n - 1

Function Signature

def print_diamond(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output