Coursera interview question

Coding: Word wrap question, leetcode hard