Amazon Interview Question

modified version of word break problem with printing the string.