Array ( [0] => [1] => questions [2] => HackwithInfy-Previous-Questions [3] => Distinct-Substrings )
Given a string, count all substrings of the given string.
First line contains string S.
Print the count of total substrings can form.
abcd
10
aaa
6
abcde
15
Login to see Discussion
Step-1: Find the length of string
Step-2: Calculate total substrings value is length of string * (length of string +1)/2
Logic:
For every Stirng:
There will be n substring of length 1
there will be n-1 substring of length 2
...
there will be 1 substring of length n
Total substrings are 1+2+3+...+n = n(n+1)/2
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution