Timer is Running

Palindromic Strings
Submissions: 17   Accuracy:


  Difficulty: Medium   Marks: 4

Given string s and an integer, you have to transform s into a palindrome. In order to achieve that you have to perform exactly k insertion of characters(you cannot perform anymore or less number of insertions). The task is to check if the string can be converted to a palindrome by making exactly k insertions.

Example 1:

Input: s = "abac", K = 2
Output: 1
Explanation: "abac" can be transformed to 
"cabbac" (which is palindrome) adding 
two characters c and b.
Example 2:
Input: s = "abcde", K = 3
Output: 0
Explanation: "abcde" cannot be transformed
to palindrome using 3 insertions.

Your Task:  
You don't need to read input or print anything. Complete the function isPossiblePalindrome() which takes s and K as input parameters and returns a boolean value

Expected Time Complexity: O(|s|2)
Expected Auxiliary Space: O(|s|2)

1 ≤ |s| ≤ 103
s contains lower case English alphabets

** For More Input/Output Examples Use 'Expected Output' option **

Author: Arnab Deb

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.