Build a Hollow Square
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
-.
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 dashes.
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
n2characters.
More Visa Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
Similar questions at other companies
- Theme Park Shuttle Wait TimeAirbnb · OAAirbnb interview questions
- Branch with the Most FilesCapital One · OACapital One interview questions
- Robot Stops Left or Right (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- REST API: Highest International StudentsRippling · OARippling interview questions
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Filter Isolated Interior Signal BitsSEDEMAC · OA
- Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
- Telephone Keypad String EncodingEpic · OAEpic interview questions
- Count Invalid Log GroupsIBM · OAIBM interview questions