Algorithm · Karat · Medium
You are building the word-wrap behavior of a word processor. To make outputs easy to check in tests, words placed on the same line are separated by dashes (-) rather than spaces. Part 1 Given a list of words and a maximum line width, break the words into lines so that each line holds as many words as it can without exceeding the width. Part 2 Extend the feature so that it takes lines of text that have already been wrapped and re-flows them to a new width. Each resulting line…