Align Wrapped Paragraph Lines
Problem statement
Each row of lines is a sequence of words, paired with LEFT or RIGHT. Greedily wrap the row using one space between words so each content line is at most width. Every word fits.
Pad each wrapped line with spaces to exactly width on the opposite side of its alignment. An empty word row emits one blank line. Return all rendered lines in row order.
Function
alignParagraphLines(lines: String[][], alignments: String[], width: int) → String[]Examples
Example 1
lines = [["hello","world"],["right"]]alignments = ["LEFT","RIGHT"]width = 11return = ["hello world"," right"]Rows are padded on opposite sides.
Example 2
lines = [["aa","bb","cc"]]alignments = ["LEFT"]width = 5return = ["aa bb","cc "]The final word moves to a second line.
Constraints
lines.length == alignments.length1 <= width <= 1000- The total word length is at most
100000.