Problem · String

BitFont Part 1 - Render a Character

Learn this problem
EasyStripe 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].

Each bitmap is a list of equal-length binary strings. A 0 is an empty pixel and a 1 is a filled pixel.

Given the lookup table and a target character, find the target's bitmap and render it by replacing every 0 with . and every 1 with #. Return the rendered rows in their original order.

Function

renderCharacter(characters: String, bitmaps: String[][], target: char) → String[]

Examples

Example 1

characters = "J"bitmaps = [["000010","000010","000010","000010","000010","000010","100010","011100","000000","000000"]]target = "J"return = ["....#.","....#.","....#.","....#.","....#.","....#.","#...#.",".###..","......","......"]

The reported J bitmap is selected from the lookup table. Each 0 becomes a period and each 1 becomes a hash while the row order and dimensions stay unchanged.

Example 2

characters = "AB"bitmaps = [["010","101","111","101"],["110","101","110","101","110"]]target = "B"return = ["##.","#.#","##.","#.#","##."]

B is the second character, so the second bitmap is selected and rendered. The first bitmap is not part of the output.

Constraints

  • 1 <= characters.length() == bitmaps.length <= 100
  • Every character in characters is unique, and target appears exactly once.
  • 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 dimensions.

More Stripe problems

drafts saved locally
public String[] renderCharacter(String characters, String[][] bitmaps, char target) {
  // write your code here
}
characters"J"
bitmaps[["000010","000010","000010","000010","000010","000010","100010","011100","000000","000000"]]
target"J"
expected["....#.", "....#.", "....#.", "....#.", "....#.", "....#.", "#...#.", ".###..", "......", "......"]
checking account