Other / Mixed Topics

Your answer
Answer & solution
Answer: D: n(n+1)/2 (no official key was published)
A substring of length k can start in n−k+1 positions. Summing for k=1 through n gives n+(n−1)+…+1=n(n+1)/2. Equivalently choose its two boundaries among n+1 boundary positions. This counts occurrences, not necessarily distinct string values: repeated characters can make different positions yield the same word. It also excludes ε. If “substrings of all lengths” includes the empty word or means distinct values, the answer needs that additional convention.