Given a binary string, task is to erase exactly one integer in the array so that the XOR of the remaining numbers is zero. The task is to count number of ways to remove one element so that XOR of that string become ZERO.
Input : 10000 Output : 1 We only have 1 ways to Input : 10011 Output : 3 There are 3 ways to make XOR 0. We can remove any of the three 1's. Input : 100011100 Output : 5 There are 5 ways to make XOR 0. We can remove any of the give 0's
A simple solution is to one by one remove an element, then compute XOR of remaining string. And count occurrences where removing an element makes XOR 0.
An efficient solution is based on following fact. If count of 1s is odd, then we must remove a 1 to make count 0 and we can remove any of the 1s. If count of 1s is even, then XOR is 0, We can remove any of the 0s and XOR will remain 0.
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Number of ways to remove a sub-string from S such that all remaining characters are same
- Number of ways to erase exactly one element in the Binary Array to make XOR zero
- Remove vowels from a string stored in a Binary Tree
- Minimum steps to remove substring 010 from a binary string
- Number of ways to make binary string of length N such that 0s always occur together in groups of size K
- Periodic Binary String With Minimum Period and a Given Binary String as Subsequence.
- Remove characters from the first string which are present in the second string
- Remove one element to get maximum XOR
- Remove one bit from a binary number to get maximum value
- Remove "b" and "ac" from a given string
- Reverse string in Python (5 different ways)
- Remove spaces from a given string
- Remove duplicates from a given string
- Ways of transforming one string to other by removing 0 or more characters
- Find all possible ways to Split the given string into Primes
- Number of ways to convert a character X to a string Y
- String obtained by reversing and complementing a Binary string K times
- C++ Program to remove spaces from a string
- Program to remove vowels from a String
- Remove all occurrences of a character in a string