minimum number of deletions to make a string palindrome

Solutions on MaxInterview for minimum number of deletions to make a string palindrome by the best coders in the world

showing results for - "minimum number of deletions to make a string palindrome"
Janae
07 Jan 2018
1//Code by @soumyadeepp : Soumyadeep Ghosh
2
3//A very Simple DP problem. Just find the length of the Longest common subsequence 
4//of the string and its reverse. Now subtract this length from the actual length
5//of the substring. That's it.
6
7#include <bits/stdc++.h>
8
9using namespace std;
10
11int lps(string s)
12{
13	string r = s;
14	reverse(r.begin(),r.end());
15	int sz1 = s.size();
16	int dp[sz1+1][sz1+1];
17	
18	for(int i = 0 ; i <= sz1 ; i++)
19	{
20		dp[0][i] = 0;
21		dp[i][0] = 0;
22	}
23	for(int i = 1; i <= sz1; i++)
24	{
25		for(int j = 1; j <= sz1 ; j++)
26		{
27			if(s[i-1] == r[j-1])
28			{
29				dp[i][j] = dp[i-1][j-1] + 1;
30			}
31			else
32			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
33		}
34	}
35	return dp[sz1][sz1];
36}
37int main()
38{
39	int t;
40	cin>>t;
41	while(t--)
42	{
43		string s;
44		cin>>s;
45		int ans = s.size() - lps(s);
46		cout<<ans<<endl;
47	}
48}
queries leading to this page
minimum characters to be added at back to make string palindromeminimum number of operations required to make string palindromeminimum number of deletions to make a string palindrome codechefminimum number of characters to be deleted to make string a palindromefind minimum number of character to make a string as palindromeminimum operations to make string palindromeminimum number of deletion to make a string palindromeminimum deletions to make string palindromeminimum number of deletions to make a string palindrome gfg practiceminimum number of insertions and deletions to make a string palindromeminimum number of deletion to make palindrome practiceminimum characters to make string palindromestring remove character to build palindromeminimum deletion to make a string palindromeremove a character from a string to make it a palindromeminimum deletion for palindromeadd minimum number of characters to make a string a palindromefind a character in string that make string stop palindromeminimum steps to make string palindromeminimum number of deletion in a string to make it a palindrome hackerrankminimum operations required to make a string palindromehow to find palindrome in string with remove charhterinsert minimum number of characters to a string to make it palindromminimum number of steps to convert string to palindromeminimum number of deletions to make a string palindromeminimum steps to delete a palindromefind the longest palindrome in a string by deletionminimum number if deletion in string to make it palindromeminimum number of operations to make an array palindromeminimum number of deletion in a string to make it a palindrome interviewbitminimum number of deletion in a string to make it a palindrome minimum number of deletion in a string to make it a palindromeremove minimum chars to make a string palindromeminimum number of deletion to convert to palindromemaximum number of deletions to get palindromeminimum deletions in a string to make it a palindromeminimum deletion to make string palindromecheck whether it is possible to make this string a palindrome after removing exactly one charactermin no of deletions to make a string palindromeminimum number of deletions to make a string palindrome