Format words into wrapped/justified lines
Company: SoFi
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates practical programming skills in string processing, greedy packing, and careful handling of spacing and edge cases, and falls under the Coding & Algorithms domain.
Part 1: Greedy Word Wrap Without Padding
Constraints
- 0 <= len(words) <= 10^4
- 1 <= len(words[i]) <= maxWidth <= 100
- Each word consists of non-space characters only
Examples
Input: (["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"], 10)
Expected Output: ["The quick", "brown fox", "jumps over", "the lazy", "dog"]
Explanation: Each line greedily takes as many words as possible without exceeding width 10.
Input: (["a", "bc", "d", "ef"], 4)
Expected Output: ["a bc", "d ef"]
Explanation: Both lines fit exactly into width 4 with one space between words.