Check if all substrings are dictionary words | Google Interview Question