Input: str = "10101"
Output: 8
Explanation: All unique substrings of given string={1, 0, 10, 01, 101, 010, 1010, 0101, 10101}.
In the above set (1010, 0101) is following the special property.
Therefore, only 1010 will be considered in the given set.
Updated Set = A = {1, 0, 10, 01, 101, 010, 1010, 10101}.
Length of A=8
Input: str = "10001"
Output: 11
Explanation: All unique substrings of given string={1, 0, 10, 01, 00, 100, 000, 001, 1000, 0001, 10001}.
In the above set no string is following the special property. Length of Set=11
WHY DOES THIS WORK?
Consider a binary string with an even number of 1's and whenever 0 is encountered in it, see how many 1's occur in it before that 0 and if it is even increase the even variable count otherwise increase the odd variable count.
Suppose, when 0 is encountered in a substring and till that it has even 1's then remaining would also be 1's(because we have considered a string with even 1's), similarly if we have odd 1's till whenever we encounter 0 therefore remaining would also be odd 1's. Therefore the reverse string would have the same parity(i.e count of 1's as even or odd). That's why it would not take the reverse string into consideration.
Below is the implementation of the above approach.