K-Palindrome-Asked in Facebook Interviews

2 min readFeb 25, 2022


Problem Statement :

Given a string, find out if the string is K-Palindrome or not.


A K-palindrome string transforms into a palindrome on removing at most k characters from it.

Input Format:

The input contains two lines.

The first line has string S.

The second line has the value ‘k’.

Output Format:

The output contains one line either “YES” or “NO” depending on whether the given string ‘S’ is a K palindrome or not.


abcdeca 2



Explanation of given Test Cases :

Here we notice that if we remove 'b' and 'd' from the given string, the remaining string is a palindrome.


The idea is to find the longest palindromic subsequence of the given string. If the difference between the longest palindromic subsequence and the original string is less than equal to k, then the string is k-palindrome else it is not k-palindrome.


Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.




Upskilling students for tech placements!