If you have a string of length n
Then you’ll have,
n strings of length 1
n-1 strings of length 2
n-2 strings of length 3
n-4 strings of length 5
.
.
.
.
3 strings of length of n-2
2 strings of length n-1
1 string of length n
Therefore total substrings will be n+(n-1)+(n-2)+(n-3)+........+3+2+1 = n(n+1)/2
_______________________________________________________________________________________________
Example : VARUN HAS LENGTH 5
5 strings of length 1 = {V,A,R,U,N}
4 strings of length 2 = {VA,AR,RU,UN}
3 strings of length 3 = {VAR,ARU,RUN}
2 strings of length 4 = {VARU,ARUN}
1 strings of length 5 = {VARUN}
Therefore total substrings will be 5+(5-1)+(5-2)+(5-3)+(5-4)+(5-5) = 5(5+1)/2 = 15
Correct Answer: D