I am Confused by the expected output


  • 0
    L

    Input: ["a","b","c","d","e"], 3
    Output: ["abc","de "]
    Expected: ["a b","c d","e "]

    I am confused with the result since I think my result do obey the rule as below:

    You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly L characters.


  • 0
    S

    In your output, there is no space among abc, but they are different words as the input given you. So there should be at least one space between each word. Your output definitely wrong.


  • 0
    L

    You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly L characters.

    pack as many word as you can in each line.so I put 'a','b','c' in the same line
    Pad extra spaces ' ' when necessary. since I already have L characters in this line
    I don't think I need extra spaces.

    where can I get the conclusion that there must have a space between two words once they are not in the last line?


  • 0
    L

    another case:
    For the last line of text, it should be left justified and no extra space is inserted between words.

    Input: ["What","must","be","shall","be."], 12
    Output: ["What must be","shallbe. "]
    Expected: ["What must be","shall be. "]

    Expected result looks elegant,but unfortunately it doesn't obey your rules


  • 0
    J

    Also confused.

    My output is

    ["a b", "cde"]

    which I think it clearly obeys the problem description

    "For the last line of text, it should be left justified and no extra space is inserted between words. "


Log in to reply
 

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