FastPrepGenerate a Hollow Star Square

Generate a Hollow Star Square

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA

Updated

Problem statement

You are given an integer n. Build an n by n hollow square as a string array.

  • Every border position contains *.
  • Every interior position contains a space character.

Return the rows from top to bottom.

Function

buildHollowSquare(n: int) → String[]

Examples

Example 1

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

The first and last rows are all border characters. Each middle row has two border stars surrounding two interior spaces.

Example 2

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

A square of side two has no interior positions, so both rows contain only stars.

Constraints

  • 2 <= n <= 1000
  • The returned output contains exactly n2 characters.

More ZipRecruiter Online Assessment questions

Similar questions at other companies

ZipRecruiter interview experiences

All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public String[] buildHollowSquare(int n) {
        // Write your code here.
    }

}
Checking account…