educative.io

Is the time complextity not 26M for each iteraction?

For each iteration you have to replace each of the 26 characters of the ascii alphabet for each of the M letters of the word. So, wouldnt we end up trying 26M different words and verify them against the words in the set for each of the eventual N words that we will be analysing in the BFS. I am not sure how O(M**2) comes up. Please let me know if i am wrong and am missing something.