129. Text Justification
Hard · String
Format a list of words into fully justified text lines. You are given an array of words and a maximum line width. Your task is to arrange the words into lines of exactly maxWidth characters each, with spaces distributed as evenly as possible between words on each line (extra spaces go left-to-right). The last line should be left-justified: words separated by single spaces, with trailing spaces padding to maxWidth. Return an array of the justified lines.
Examples
Example 1 Input: [["This","is","an","example","of","text","justification."], 16] Output: ["This is an","example of text","justification. "] Explanation: Each line is exactly 16 chars; last line left-justified
Example 2 Input: [["hello"], 7] Output: ["hello "] Explanation: Pad with trailing spaces
Constraints
- Standard input/output constraints apply