Problem 2: Peragrams
https://open.kattis.com/problems/peragrams
Palindromes are symmetrical, so each character—except possibly the middle character—is repeated. Examples:
abcba
- all characters except the middle character are repeatedabba
- all characters repeated (no middle character)
A string is a peragram if at most one character appear in the string an odd number of times, while all other characters appear an even number of times.
To figure out the number of characters that must be removed from a string to make a peragram:
Count the number of occurrences of each letter (can be done using an array/vector of 26 integers)
Ignore all letters with an even # of occurrences, and ignore the first letter with an odd # of occurrences (if it exists)
For all remaining letters, delete exactly one character to convert to an even # of occurrences
Last updated