BitFont Part 2 - Render a Word
Learn this problemProblem statement
Practice sequence
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() <= 1001 <= characters.length() == bitmaps.length <= 100- Every character in
charactersis unique, and every character intextappears incharacters. - Each bitmap contains between
1and100rows. - Every row in one bitmap has the same length, between
1and100. - Every bitmap row contains only
0and1. - Different characters may use different bitmap heights and widths.