Amazon interview question

modified version of word break problem with printing the string.