Facebook Pixel

What is the logic for a hollow square?

Generate an N x N grid and print a star only if the current row or column is at the absolute boundary (1 or N). Otherwise, print a space.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Printing a Hollow Square Star Pattern

You could, but it is incredibly messy. Coordinate-based boolean logic is the standard and most readable way to handle hollow shapes.

Because terminal fonts are usually taller than they are wide. A star (*) takes up more vertical space than horizontal space. You can fix this by printing '* ' (with a space) to widen the shape.

This exact boundary logic (checking if row==0 or col==max) is used in graph traversal algorithms (like BFS/DFS in a matrix) to detect when you hit a wall.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.