help.
Asked by: Shubham_Agarwal1 on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
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[0] to str[4]), 1 (str[0]), 1 (str[4]). 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.