https://www.codechef.com/problems/CSUB

codechef

help.
nocode_phobiat
Shubham Agarwal
nocode_phobiat

Please Log in to answer

Note: Your answer should not be too short. Please wait a few seconds for the editor to load



Please make sure the answer is not too short

1 Answer

preda2or
preda2or 13:39, Oct 12
Shubham Kumar Gupta

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.




Please make sure the answer is not too short
1 Upvotes
Comments
preda2or (Shubham Kumar Gupta) 00:15, Oct 13

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.

Proma (Proma Roy) 22:54, Oct 12

But how can we get the logic??....Do we have to consider a number of strings and then derive the logic??