Failed test case when solved using DP:


  • 0
    S

    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 ?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.