Format a Centered Paragraph in a Star Frame
Updated
Problem statement
Join sentences with one space, split on whitespace, and greedily pack words into content lines of at most width characters using one space between words. Every word fits within width.
Return a frame whose top and bottom are width + 2 stars. Each content row has side stars and exactly width interior characters. Center a line with spaces; when the unused count is odd, put the extra space on the right. If there are no words, emit one empty centered content row.
Function
frameParagraph(sentences: String[], width: int) → String[]Examples
Example 1
sentences = ["hello world from zip"]width = 10return = ["************","* hello *","*world from*","* zip *","************"]Words are greedily packed and each line centered.
Example 2
sentences = ["abc"]width = 6return = ["********","* abc *","********"]The extra odd space is placed on the right.
Constraints
1 <= width <= 1000- The total sentence 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