some thoughts about the question
In fact, it\'s not that hard to have brute force solution. The below is my naive idea. Grow word up and check newly generated word consisting evil word or not.\
In fact, it\'s not that hard to have brute force solution. The below is my naive idea. Grow word up and check newly generated word consisting evil word or not.\n\nBut it\'s really easy to get TLE for the question since length of word can be 500 mentioned in the condition. My solution should take O(26^n) * O(n) for the worst case. Former one for brute force iteration and latter one for indexOf() method.  The optimization the real hardest part for the question. The better solution is definitely related to rolling hash. I am currently thinking we should avoid brute force, but try using evil words directly to generate invalid words instead. Hence we can use the total amount from s1 to s2 then substract with the amount of invalid words. However this will be extremly hard for corner case and i just give up. Well, this is just a guess. Any we need Lee for sure! LOL\n\n\tclass Solution {\n\t\tpublic int findGoodStrings(int n, String s1, String s2, String evil) {        \n\t\t\tint count = 0;\n\n\t\t\twhile(!s1.equals(s2)) {\n\t\t\t\tif(s1.indexOf(evil) == -1) count++;\n\t\t\t\ts1 = addOne(s1.toCharArray());\n\t\t\t}\n\n\t\t\treturn s2.indexOf(evil) == -1 ? count + 1 : count;\n\t\t}\n\n\t\tprivate String addOne(char[] chars) {\n\t\t\tint i = chars.length - 1;\n\n\t\t\twhile(i >= 0) {\n\t\t\t\tchars[i]++;\n\n\t\t\t\tif(chars[i] <= \'z\') {\n\t\t\t\t\treturn new String(chars);\n\t\t\t\t} else {\n\t\t\t\t\tchars[i] = \'a\';\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn "";\n\t\t}\n\t}
[]