If we imagine a worst case as the grid consisting of the letters that each start a word of length that spans the entire grid, which is n * n, then (as given by the solution) we loop over each element of the grid, which is n * n times. So for each character in the grid that we start from, we have to explore n * n - 1 other characters.
For example grid:
a, b, c
d, e, f
g, h i
"abcdefghi", "bacdefghi", cbadeghgi", .... "ihgfedcba"
Type your question above this line.