In this question we have to find the no of substrings starting and ending both with '1'.
for input string (str) : 10001
the substrings are : 10001 (str to str), 1 (str), 1 (str). Hence, answer is 3.
Note that a substring of length one which contains the character '1' is also starting and ending with 1, hence it will also add to our answer.
if we use maths it will save us the trouble to consider every such string.The result will be
( nC2 )+n, where n = no of 1's in given string.
But how can we get the logic??....Do we have to consider a number of strings and then derive the logic??