FastPrepPrint a Diamond Pattern
Problems/Print a Diamond Pattern

Print a Diamond Pattern

Apple logoApple● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple new grad phone screen. The report briefly recalls printing a diamond shape. Our version is about 60% the same as the reported question. We chose a filled pattern, how size works, the spacing, and the input limits.

Given an integer n, return the lines of a filled diamond made of asterisks (*). The top half, including the center row, contains n rows. The bottom half mirrors the top half and excludes a second copy of the center.

There are exactly 2*n - 1 lines. For a zero-based row r, let d = |r - (n - 1)|. The line contains exactly d leading spaces followed by 2*(n - d) - 1 asterisks.

Use ordinary ASCII spaces. Preserve leading spaces, include no trailing spaces, and do not include newline characters inside any returned string.

Function

diamondLines(n: int) → String[]

Examples

Example 1

n = 1return = ["*"]

The minimum diamond contains one row with one asterisk.

Example 2

n = 3return = ["  *"," ***","*****"," ***","  *"]

The asterisk counts are 1,3,5,3,1, with 2,1,0,1,2 leading spaces. The center appears once.

Constraints

  • 1 <= n <= 30.

More Apple Phone Screen questions

  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
  • Evaluate DivisionPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
  • Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
  • Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
  • Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
  • Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
  • Roman to IntegerKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Minimum Difference Between Two Clock TimesMicron Technology · PHONE SCREEN
  • Decimal Digits in OrderZoomInfo · PHONE SCREEN
  • Add Two Integers Given as StringsJane Street · PHONE SCREENJane Street interview questions
  • Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
  • Integer to String Without Built-insHudson River Trading · PHONE SCREENHudson River Trading interview questions

Interview reports that mention this question

  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
  • Apple New Grad SWE Interviews: 37 Experiences (Part 1 of 3)

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public String[] diamondLines(int n) {
        // Write your solution here.
    }

}
Checking account…