K-Palindrome-Asked in Facebook Interviews

Problem Statement :

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

Note:-

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.

Given:

Output:

Explanation of given Test Cases :

Approach:

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.

Code:

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store