check Word Break or not in 1D dynamic programming