Finished substrings problem