Problem
Give a Binary String of size , return the number of Odd Parity substrings to be generated from a string.
Solution (Linear Time)
Assuming we are given a zero-indexed string Define a function
Then, will be the solution.
Give a Binary String of size n, return the number of Odd Parity substrings to be generated from a string.
Assuming we are given a zero-indexed string x Define a function
f(i)=⎩⎨⎧01f(i−1)+g(i)if i=1 and x[0]=0if i=1 and x[0]=1if 1<i≤len(x) g(i)=⎩⎨⎧01g(i−1)i−g(i−1)if i=1 and x[0]=0if i=1 and x[0]=1if 1<i≤len(x) and x[i−1]=0if 1<i≤len(x) and x[i−1]=1Then, f(len(x)) will be the solution.