You have a permutation of N numbers and you want to change it into a palindrome. You can perform only a
single operation as many times as you want, that is choose any two numbers and replace them with their sum.
What will be the minimum operations you need to change the permutation into a palindrome?
Answers
Given a string containing all digits, we need to convert this string to a palindrome by changing at most K digits. If many solutions are possible then print lexicographically largest one.
Examples:
Input : str = “43435”
k = 3
Output : "93939"
Explanation:
Lexicographically largest palindrome
after 3 changes is "93939"
Input : str = “43435”
k = 1
Output : “53435”
Explanation:
Lexicographically largest palindrome
after 3 changes is “53435”
Input : str = “12345”
k = 1
Output : "Not Possible"
Explanation:
It is not possible to make str palindrome
after 1 change.
Answer:
You have a permutation of N numbers and you want to change it into a palindrome. You can perform only a
single operation as many times as you want, that is choose any two numbers and replace them with their sum.
What will be the minimum operations you need to change the permutation into a palindrome?