Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Print Diamond Pattern
00:00
5 left

Print Diamond Pattern

EasyPython

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):
Interviewer

Your question is Print Diamond Pattern. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.