Align Wrapped Paragraph Lines
Updated
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.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Maximum String OperationsMicrosoft · OAMicrosoft interview questions
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
- Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
- Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
- Minimum Binary Swaps to a PalindromeAT&T · OAAT&T interview questions
- Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimum Additions to Make a Valid ABC StringIBM · OAIBM interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Minimum Adjacent TranspositionsEpic · OAEpic interview questions