Reported December 2023
ZipRecruitersimulation

Generate a Hollow Star Square

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

Brute force isn't the worry here, because n tops out at 1000 and the output is exactly n squared characters. The ZipRecruiter OA, reported in December 2023, asks you to build a hollow star square as a string array. It's a simulation problem with string construction, and it's a warm-up, not a trap. You'll lose points on off-by-one mistakes and the n = 2 edge case, not on difficulty. If you freeze on a simple one, StealthCoder sits invisibly on your screen during the live OA as a safety net. Read the pattern below and you probably won't need it.

The problem

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 = 4
return = ["****","* *","* *","****"]
The first and last rows are all border characters. Each middle row has two border stars surrounding two interior spaces.
Example 2
n = 2
return = ["**","**"]
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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that every row is one of two shapes. Row 0 and row n-1 are n stars. Every other row is a star, then n-2 spaces, then a star. Build each string once and reuse it. In Python that's '*' * n for the border and '*' + ' ' * (n-2) + '*' for the middle, then assemble the list. The pitfall is a nested loop with per-character checks that gets the boundary condition wrong, or string concatenation in a loop that gets slow in some languages. Another miss is n = 2, where n-2 is zero, so the middle rows are just two stars, which still works with the formula. Time is O(n^2) because that's the output size, and you can't beat it. If you blank on the setup during the live OA, StealthCoder is the hedge that hands you the working code. Otherwise, write it in five lines.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Generate a Hollow Star Square cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Generate a Hollow Star Square FAQ

How hard is the ZipRecruiter hollow star square problem really?+

It's easy. The input is a single integer between 2 and 1000, and the output is a list of strings. There's no algorithm beyond building two row patterns. Most candidates finish in a few minutes. The only real risk is a sloppy boundary check or forgetting the n = 2 case.

What's the trick to solving it fast?+

Notice there are only two row types. The top and bottom rows are all stars. Every middle row is a star, n-2 spaces, and a star. Build those two strings once, then place them. You skip per-cell conditionals and the off-by-one bugs that come with them.

Does n = 2 break anything?+

Not if you use the formula. With n = 2, n-2 is zero, so the middle pattern is two stars with nothing between them. But a square of side two has only two rows, both border rows, so the output is just two rows of two stars, matching Example 2.

What's the time and space complexity?+

Both are O(n^2), since the output holds exactly n squared characters. You can't go lower because you must return every character. With n up to 1000, that's about a million characters, which is fine for any language. Reusing the two row strings keeps the work simple.

How do I prepare for this in 48 hours?+

Don't over-prep for this one. Practice a few string-building and grid-printing problems so the loop and slicing syntax in your language is automatic. Check edge cases like the smallest n. Spend the rest of your time on harder problems, since the OA will likely include more than this one.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it