Question: Problem stotement You are given a binary string ' S ' , i . e . ' Stj ' ' is either ' 0 '

Problem stotement
You are given a binary string 'S', i.e.'Stj''is either '0' or '11. For this task, you are
asked to retum the sum of the length of all the substring which contains an odd
number of 1 :
For Exomple:
S=010101
Here, the substrings with an odd number of "19s are "1","10","10101","01",
"010","1","10","01", and "1".
Therefore, we retum 19 for the given example.
Detoiled explongition (Input/output format, Notes, Images)
Constuints:
1> Slength >1015
0'>S[]>11
ime Limit 1 second
Sample Input 1:
100101
Sample Outout 1:
Sample Input is
100101
Sample output 1:
30
Explanation :
All the substrings with odd numbers of 1's are "1","10",
"100","100101","601","0010","01","010","1","10","01"
and "1". Therefore the sum of length will be
1+2+3+6+3+4+2+3+1+2+2+1=30
Hence we return 30.
Sample Input 2:
101010
Sample output 2:30

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!