Problem Β· String

BitFont Part 2 - Render a Word

Learn this problem
● MediumStripe logoStripeFULLTIMEONSITE INTERVIEW
See Stripe hiring insights

Problem statement

Practice sequence

  1. Part 1: Render a Character
  2. Part 2: Render a Word
  3. Part 3: Decode RLE Rows

A bitmap font stores one bitmap for each supported character. The lookup table is represented by two parallel inputs: characters[i] names the character whose bitmap is stored in bitmaps[i].

Render text by placing its character bitmaps side by side with no columns inserted between them. Build each output row from left to right, then replace every 0 with . and every 1 with #.

Row alignment

If text is empty, return an empty array. Otherwise, the output height is the number of rows in the first character's bitmap.

For each later character, use its row at the current output row when that row exists. If the character has fewer rows, append an all-zero row with that character's width. If it has more rows than the first character, ignore the extra bottom rows.

Function

renderWord(text: String, characters: String, bitmaps: String[][]) β†’ String[]

Examples

Example 1

text = "ABA"characters = "AB"bitmaps = [["010","101","111"],["10","11"]]return = [".#.#..#.","#.####.#","###..###"]

The first A gives the output height of three rows. On the third row, B has no bitmap row, so its two-column width contributes 00. The binary row 11100111 renders as ###..###.

Example 2

text = ""characters = "A"bitmaps = [["1"]]return = []

An empty text returns an empty rendered picture.

Example 3

text = "BA"characters = "AB"bitmaps = [["010","101","111"],["10","11"]]return = ["#..#.","###.#"]

The first character B has two rows, so only two output rows are produced. The third row of A is not used.

Constraints

  • 0 <= text.length() <= 100
  • 1 <= characters.length() == bitmaps.length <= 100
  • Every character in characters is unique, and every character in text appears in characters.
  • Each bitmap contains between 1 and 100 rows.
  • Every row in one bitmap has the same length, between 1 and 100.
  • Every bitmap row contains only 0 and 1.
  • Different characters may use different bitmap heights and widths.

More Stripe problems

drafts saved locally
public String[] renderWord(String text, String characters, String[][] bitmaps) {
  // write your code here
}
text"ABA"
characters"AB"
bitmaps[["010","101","111"],["10","11"]]
expected[".#.#..#.", "#.####.#", "###..###"]
checking account