Input

["Here","is","an","example","of","text","justification."]

14

Expected output is :

[ 'Here is an', = (4 addl. spaces)

'example of', = (4 addl. spaces)

'text ', = (9 addl. spaces)

'justification.' ] = (0 addl. spaces)

A more optimal output is as below because the additional spaces are properly distributed

across lines

[ 'Here is an', (4 addl. spaces)

'example ', (6 addl. spaces)

'of text', (7 addl. spaces)

'justification.' ] (0 addl. spaces)

I have used dynamic programming to solve the minimize badness across lines where badness is defined as follows =

(line width - space occupied by words ) ^3

Infinity if a given range of words does not fit the line

Did anyone else hit the same issue ?