dynamic programming string merge validation see input and output