Just a substring is determined by two parameters [i,j], which are the starting index of the index and the end for the substring in the source string. Now 0<=i,j<=n, since codes must be in line, Total values i&jeach may have n, therefore, all combinations [i,j]are n*nthat areO(n^2)