Quick Overview

This question evaluates skills in binary-to-text data representation, bitmap rendering, and efficient string and array manipulation for output formatting.

Convert bitmap into ASCII characters

Company: Stripe

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

##### Question Given an array/string of 0-1 bits representing a bitmap font, write code to render each character as a grid using '.' for 0 and '#' for 1, and concatenate multiple characters to print whole words efficiently.

Quick Answer: This question evaluates skills in binary-to-text data representation, bitmap rendering, and efficient string and array manipulation for output formatting.

You are given a bitmap font and a text to render. The font is a mapping from single characters to a row-major bitstring of length width * height. Each bit '1' renders as '#', and each bit '0' renders as '.'. Render the given text by placing glyphs side-by-side, inserting exactly one '.' column between adjacent characters. The space character ' ' is treated as a blank glyph of width columns (all '.'). If any non-space character in text is missing from the font or has an invalid bitstring length, raise a ValueError. Return the rendered result as a list of height strings (top to bottom).

Constraints

  • 1 <= width <= 32
  • 1 <= height <= 32
  • 1 <= len(text) <= 10000
  • Each font entry's bitstring length is exactly width * height
  • Bits are only '0' or '1'
  • Space ' ' renders as a blank glyph of width columns (all '.')

Hints

  1. Interpret each glyph's bitstring in row-major order: rows of length width, from top to bottom.
  2. Build the output row-by-row: append each glyph's row to the corresponding output row, then add a '.' separator if not the last character.
  3. Cache decoded glyph rows to avoid repeated conversions when characters repeat.

Loading coding console...