Given a binary string consisting of 0s and 1s only and an integer K We have to make the value of the
string K by a minimum number of operations.
Steps to calculate the value of the string:-
Cut the string into the minimum number of disjoint substrings such that every substring has the same character ('0' or '1').The substring value is the number of characters present in it.
The value of the string is the xor of all the values of the disjoint substrings.
Example string is '0001110111000 its value would be (3^1^3^3^3=1). We will cut
the string like "000","111", "O","111","000" and substring values would be [3,3,1,3,3].
Note ^ operator denotes XOR.
In one operation we can only swap consecutive values.
So given a binary string, we have to make the value of the string K in the minimum number of operations.
Print the minimum number of operations to do so.
If it is impossible to do so. print -1.
Example
Consider s = 1001, K = 0.
Currently, the value of S is 1^2^1 that is 2.
We can swap first two characters. S becomes 0101 and the value of S will be 0. So, the answer will be 1
Example
String is 00111001.K=0.
Explanation-Initially , the value of the string is (2^3^2^1=2). If we swap 2nd and 3rd character, string becomes "01011001", its value becomes 0.So the output will be minimum 1 operation required.
Constraints
1<=Number of zeros in string<=45
1<=Number of ones in string<=45
1<=K<=10^12