509. Valid Palindrome IV

You are given a 0-indexed string s consisting of only lowercase English letters. In one operation, you can change any character of s to any other character.

Return true if you can make s a palindrome after performing exactly one or two operations, or return false otherwise.

Example 1:

Input: s = "abcdba"

Output: true

Explanation: One way to make s a palindrome using 1 operation is:

- Change s[2] to 'd'. Now, s = "abddba".

One operation could be performed to make s a palindrome so return true.

Example 2:

Input: s = "aa"

Output: true

Explanation: One way to make s a palindrome using 2 operations is:

- Change s[0] to 'b'. Now, s = "ba".

- Change s[1] to 'b'. Now, s = "bb".

Two operations could be performed to make s a palindrome so return true.

Now Your Turn!

Pick the correct output for the given input

Consider the string "racebr". Can it be turned into a palindrome using exactly one or two operations?

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s consists only of lowercase English letters.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
bool makePalindrome(string s) {
// Your code goes here
}
};
Test Case

Input:

Nums