FastPrepAlign Wrapped Paragraph Lines
Problems/Align Wrapped Paragraph Lines

Align Wrapped Paragraph Lines

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter new-grad OA report describes paragraph strings in groups, a left or right alignment mode, and fixed-width formatting. We supplied greedy word wrapping, joining words with single spaces, padding, empty rows, the output shape, and leaving out words that are too long. Our version is about 78% the same as the reported question.

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.length
  • 1 <= 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

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public String[] alignParagraphLines(String[][] lines, String[] alignments, int width) {
        // Write your code here.
    }

}
Checking account…