- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

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

# Minimum removal to make palindrome permutation in C++

## Problem statement

Given a string S, we have to find minimum characters that we can remove to make any permutation of the string S a palindrome

## Example

If str = “abcdba” then we remove to 1 character i.e. either ‘c’ or ‘d’.

## Algorithms

1. There can be two types of a palindrome, even length, and odd length palindromes 2. We can deduce the fact that an even length palindrome must have every character occurring even number of times 3.An odd palindrome must have every character occurring even number of times except one character occurring odd number of time 4. Check the frequency of every character and those characters occurring odd number of times are then counted. Then the result is total count of odd frequency characters’ minus 1

## Example

#include <bits/stdc++.h> #define MAX 26 using namespace std; int minCharactersRemoved(string str) { int hash[MAX] = {0}; for (int i = 0; str[i]; ++i) { hash[str[i] - 'a']++; } int cnt = 0; for (int i = 0; i < MAX; ++i) { if (hash[i] & 1) { ++cnt; } } return (cnt == 0) ? 0 : (cnt - 1); } int main(){ string str = "abcdba"; cout << "Minimum characters to be removed = " << minCharactersRemoved(str) << endl; return 0; }

When you compile and execute above program. It generates following output

## Output

Minimum characters to be removed = 1

- Related Questions & Answers
- Palindrome Removal on C++
- Palindrome Permutation II in C++
- Minimum Insertion Steps to Make a String Palindrome in C++
- Minimum number of deletions to make a string palindrome in C++.
- Minimum number of Appends needed to make a string palindrome in C++
- Using Counter() in Python 3.x. to find minimum character removal to make two strings anagram
- Find minimum number of merge operations to make an array palindrome in C++
- Program to check minimum number of characters needed to make string palindrome in Python
- Program to count number of minimum swaps required to make it palindrome in Python
- Checking for permutation of a palindrome in JavaScript
- Program to find minimum number of characters to be added to make it palindrome in Python
- Counting steps to make number palindrome in JavaScript
- Maximum edge removal from tree to make even forest in C++
- Can Make Palindrome from Substring in Python
- Program to split two strings to make palindrome using Python

Advertisements