Indeed interview question

return a substring given maximum length so that the substring ends with a complete word.