Implement an ASCII Art Printer
AsanaSoftware Engineer · OnsiteLast updated
This question evaluates the ability to implement text rendering and string/array manipulation concepts, including glyph concatenation with inter-character spacing, newline-preserved blocks, blank glyph rendering for spaces, and handling of unsupported characters.
Implement an ASCII art printer.
A font defines each supported character as a glyph with the same height. A glyph is a list of equal-length text rows. Given an input string and the font, return the rendered ASCII-art output.
Requirements:
- Render characters by concatenating corresponding glyph rows horizontally.
- Insert one blank column between adjacent characters on the same input line.
- Preserve newline characters in the input by starting a new block of glyph rows.
- Render a space character as a blank glyph of the font height.
- For an unsupported character, either return an error or render a configured placeholder; document your choice.
- Do not print directly to stdout; return the final string or list of lines.
Example font of height 3:
| Character | Row 1 | Row 2 | Row 3 |
|---|---|---|---|
A | # | # # | ### |
B | ## | # # | ## |
Input AB with one-column spacing renders:
# ##
# # # #
### ##
Constraints: let S be the total number of characters in the rendered output. The implementation should run in O(S) time.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.