Here is the interview question prompt, presented for reference.
Can you justify input text represented by an array of words so it looks pretty when printed and the whitespaces are balanced?
For example, in the above image, we have an input array of ["wow", "so", "cool", "is", "algodaily!"]
. This is a list of words we need to properly arrange, with the ideal number of spaces in between, to balance out the layout.
O(n^2)
O(n)
An obvious solution for text justification is to fit as many words as possible in all the lines. So with ["wow", "so", "cool", "is", "algodaily!"]
, and an example layout of 10
spaces: we'd place all 3 words: "wow", "so", and "cool", into one single line with no spaces. However, the text would not look pretty if such a naïve scheme is used for justifying text.
A better idea is to evenly distribute spaces on all lines of text for a more aesthetically looking display. This is obvious from the figure shown above, where arrangement 2 is more balanced than arrangement 1.
You can see the full challenge with visuals at this link.
Challenges • Asked almost 7 years ago by Jake from AlgoDaily
This is the main discussion thread generated for Text Justification.
Can you please correct the question statement as the line width is 11 & not 10