- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Ways to remove one element from a binary string so that XOR becomes zero in C++

In this problem, we are given a binary string. Our task is to count the total number of ways in which we can remove one element such that XOR becomes zero.

Let’s take an example to understand the problem,

## Input

n = 11010

## Output

3

to solve this problem, we need the logic that if the number of 1’s is even then XOR of the string will be 0, otherwise, we need to remove one 1 from the string. We can remove any number of 0’s without affecting the XOR.

Program to show the implementation of our solution,

## Example

#include<iostream> #include<string.h> using namespace std; int wayXorZero(string binaryString){ int oneCount = 0, zeroCount = 0; int n = binaryString.length(); for (int i = 0; i < n; i++) if (binaryString[i] == '1') oneCount++; else zeroCount++; if (oneCount % 2 == 0) return zeroCount; return oneCount; } int main(){ string binaryString = "10110100"; cout<<"Number of ways to make XOR zero is "<<wayXorZero(binaryString); return 0; }

## Output

Number of ways to make XOR zero is 4

- Related Articles
- C++ Program to remove Characters from a Numeric String Such That String Becomes Divisible by 8
- Minimum flips in two binary arrays so that their XOR is equal to another array in C++.
- Minimum steps to remove substring 010 from a binary string in C++
- Remove One Bit from a Binary Number to Get Maximum Value in C++
- Minimum operations to make XOR of array zero in C++
- Add minimum number to an array so that the sum becomes even in C++?
- Find the minimum value to be added so that array becomes balanced in C++
- Python - Ways to remove a key from dictionary
- Remove vowels from a String in C++
- C++ Program to remove spaces from a string?
- C++ program to remove minimum elements from either side such that 2*min becomes more than max
- Print all possible ways to convert one string into another string in C++
- Program to remove all nodes with only one child from a binary tree in Python?
- Add minimum number to an array so that the sum becomes even in C programming
- Remove Zero Sum Consecutive Nodes from Linked List in C++

Advertisements