#K47267. Palindrome Transformation
Palindrome Transformation
Palindrome Transformation
You are given a string s
and two non-negative integers m
and n
. You are allowed to remove at most m
characters from s
and add at most n
characters to s
. Determine whether it is possible to rearrange s
(after the modifications) into a palindrome.
A palindrome is a string that reads the same forward and backward. A necessary condition for a string to be rearranged into a palindrome is that at most one character can have an odd frequency. In this problem, you are permitted to modify the string in order to achieve this condition.
The condition to check can be expressed in LaTeX as follows:
$$\text{odd\_count} \le m + 2n + 1,$$
where odd_count
represents the number of characters in s
that appear an odd number of times.
inputFormat
The input consists of a single line containing a string s
followed by two space-separated integers m
and n
.
Constraints:
s
consists of lowercase English letters only.m
andn
are non-negative integers.
outputFormat
Output a single line containing either YES
if it is possible to rearrange the adjusted string into a palindrome, or NO
otherwise.
abac 1 1
YES