BitFont - Maximum Non-Overlapping Kerning
Problem statement
Two selected bitmap glyphs are supplied as leftGlyph and rightGlyph. Each glyph is a rectangular list of binary row strings. A 1 is ink and a 0 is background. Both glyphs have the same height.
Placement rules
Let L and R be the glyph widths. The left glyph starts at column 0. A kerning value k, with 0 <= k <= L, places the right glyph at column L - k. Thus k = 0 puts the glyphs side by side, and a larger value moves the right glyph closer.
A placement is valid when no output cell receives ink from both glyphs. Background columns and even the glyph bounding boxes may overlap. Evaluate each final placement independently: an invalid smaller value does not rule out a larger valid value. The right glyph may start at column 0, but never at a negative column.
Return the largest valid k. The placement at k = 0 always has disjoint glyph extents, so a result always exists.
Do not stop at the first collision while increasing k. For example, with leftGlyph = ["101"] and rightGlyph = ["010"], values 0, 1 and 3 are valid, while 2 collides. The answer is 3.
Function
maximumKerning(leftGlyph: String[], rightGlyph: String[]) → intExamples
Example 1
leftGlyph = ["101"]rightGlyph = ["010"]return = 3The largest valid final-placement shift is 3. The right origin is 0. Every larger allowed shift is invalid; smaller collisions do not exclude this final placement.
Example 2
leftGlyph = ["11","11"]rightGlyph = ["1","1"]return = 0The largest valid final-placement shift is 0. The right origin is 2. Every larger allowed shift is invalid; smaller collisions do not exclude this final placement.
Example 3
leftGlyph = ["0010","0100"]rightGlyph = ["100","001"]return = 4The largest valid final-placement shift is 4. The right origin is 0. Every larger allowed shift is invalid; smaller collisions do not exclude this final placement.
Constraints
1 <= leftGlyph.length == rightGlyph.length <= 100.- Every row in
leftGlyphhas the same widthL; every row inrightGlyphhas the same widthR. 1 <= L, R <= 100.- Rows contain only ASCII
0and1. Entirely background rows or glyphs are allowed.