Implement text formatter and sum subarray products | Pika
|Home/Coding & Algorithms/Pika
Implement text formatter and sum subarray products
Pika
Aug 12, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
0
0
Text formatter (LC-inspired variant): Given an array of words and an integer maxWidth W >= 1, break the words into lines so that the total length of words on each line plus spaces is at most W. For every line except the last, place exactly one space between adjacent words, then append all remaining padding spaces after the final word so the line length is exactly W. The last line should be left-justified with single spaces between words and any remaining spaces appended at the end to reach W. Do not split words. Return the list of lines as strings and explain your algorithm and its time/space complexity.
Sum of subarray products: Given an integer array items[0..n-1], compute S = ∑
{i=0}^{n-1} ∑
{j=i}^{n-1} (∏_{k=i}^{j} items[k]). Return S.