Problem · String

BitFont Part 2 - Render a Word

MediumStripeONSITE INTERVIEW
See Stripe hiring insights

This continues the bitmap-font renderer. A font maps each character name to its glyph grid (a list of equal-length 0/1 rows). All glyphs in a font share the same height but may have different widths.

Render a word by joining the per-character glyphs side-by-side with no spacing between letters, producing one multi-row grid, then convert that grid to symbols (0 becomes ., 1 becomes #). Concatenate the binary rows of every glyph first, then convert. Return the rendered picture as a list of strings.

An empty text returns an empty list. The output height equals the height of the glyphs in the font.

Font encoding for this problem: font is a String[] where each entry is "name:row1|row2|...|rowH" — the character name, a colon, then the glyph's binary rows separated by |. For example, the glyph for H with rows 10001,10001,11111,10001,10001 is encoded as "H:10001|10001|11111|10001|10001".

Examples
01 · Example 1
text = "HI"
font = ["H:10001|10001|11111|10001|10001", "I:111|010|010|010|111"]
return = ["#...####", "#...#.#.", "#####.#.", "#...#.#.", "#...####"]
The H glyph (width 5) and I glyph (width 3) are concatenated flush row-by-row. Row 0 is 10001+111 = 10001111 -> #...####. Row 2 is 11111+010 = 11111010 -> #####.#. and so on. There is no spacing between the letters.
02 · Example 2
text = ""
font = ["H:10001|10001|11111|10001|10001", "I:111|010|010|010|111"]
return = []
An empty word produces an empty rendered picture.
Constraints
  • Every character in text has a glyph entry in font.
  • All glyphs in the font share one height; widths may differ.
  • Concatenate glyph rows with no inter-letter spacing, then map 0 to . and 1 to #.
  • An empty text returns [].
  • Font entries are "name:row1|row2|...".
More Stripe problems
drafts saved locally
public String[] renderWord(String text, String[] font) {
  // write your code here
}
text"HI"
font["H:10001|10001|11111|10001|10001", "I:111|010|010|010|111"]
expected["#...####", "#...#.#.", "#####.#.", "#...#.#.", "#...####"]
sign in to submit