The word-wrap logic wasn't that bad once I thought of it as accumulating glyph widths and checking against the max.
Start by clarifying the spec: how whitespace breaks are preferred, how glyph rows are aligned, and how spacing/padding is applied. Then outline a two-phase algorithm: first tokenize the input into words and measure their pixel widths, then greedily pack words into lines respecting the max width and whitespace preference. Finally, discuss how to render each line with consistent row heights and apply spacing/padding exactly as specified.
Pro tip: Mention that you would write unit tests for edge cases like a single word longer than the max width, multiple consecutive spaces, and empty lines—this shows you think about robustness and spec compliance, which Stripe values.
Ask about whitespace handling (e.g., collapse multiple spaces, break at spaces vs. hyphens), padding rules (left/right/top/bottom), and whether glyph rows must be flush (aligned to a common baseline or top). Confirm the max width is in pixels, not characters.
Represent each glyph as a 2D bitmap with known width/height. Precompute the pixel width of each character and space. For words, sum character widths plus inter-character spacing (if any). This allows efficient line-breaking decisions.
Tokenize input into words and whitespace. Greedily add words to the current line while the total width (including spaces) ≤ max width. If a word doesn't fit, start a new line. If a single word exceeds max width, either break it at character boundaries or allow overflow—clarify with interviewer.
For each line, determine the maximum glyph height among its characters. Pad shorter glyphs (top or bottom) so all rows are flush. Then concatenate glyph bitmaps horizontally, inserting spaces between words and applying any specified padding.
Apply exact spacing rules: e.g., one space between words, no trailing spaces, and padding around the entire block. Ensure padding is added after line-breaking, not before, to avoid affecting width calculations.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.