Implement an ASCII Art Printer
Company: Asana
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: 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.
Constraints
- font contains at least one glyph
- 1 <= H, W <= 10
- Every glyph in font has exactly H rows, and every row has length W
- 0 <= len(text) <= 10^4
- Your algorithm should run in O(S) time, where S is the number of characters in the returned output
Examples
Input: ('AB', {'A': [' # ', '# #', '###'], 'B': ['## ', '# #', '## ']}, None)
Expected Output: ' # ## \n# # # #\n### ## '
Explanation: Rows 1, 2, and 3 of A and B are concatenated with one extra blank column between the two glyphs.
Input: ('A\nB', {'A': [' # ', '# #', '###'], 'B': ['## ', '# #', '## ']}, None)
Expected Output: ' # \n# #\n###\n## \n# #\n## '
Explanation: The newline in the input starts a new block of 3 glyph rows, so A is rendered first and B is rendered below it.
Input: ('A B', {'A': [' # ', '# #', '###'], 'B': ['## ', '# #', '## ']}, None)
Expected Output: ' # ## \n# # # #\n### ## '
Explanation: The space character is rendered as a blank 3x3 glyph, and there is still one blank column between adjacent characters.
Input: ('AZ', {'A': [' # ', '# #', '###'], '?': ['???', ' ?', ' ? ']}, '?')
Expected Output: ' # ???\n# # ?\n### ? '
Explanation: Z is not in the font, so the placeholder glyph for ? is used instead.
Input: ('', {'A': [' # ', '# #', '###']}, None)
Expected Output: ''
Explanation: An empty input string produces an empty output string.
Hints
- Render one input line into H separate row buffers, one buffer for each glyph row.
- Avoid repeated string concatenation inside loops; collect fragments in lists and join them at the end.