eBay interview question

Basically is leetcode 68. Text Justification