➤ Problem Link : AIBOHP
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
int dp[6101][6101];
int main()
{
int t;
cin>>t;
while(t--)
{
int i,j;
string s;
cin>>s;
int l=s.length();
for(int i=0;i<l;i++)
{
for(int j=0;j<l;j++)
{
if(i==j)
dp[i][j]=0;
else
dp[i][j]=INT_MAX;
}
}
for(int k=1;k<l;k++)
{
for(i=0,j=k;i<l,j<l;i++,j++)
{
if(s[i]==s[j] && j-i>=2)
dp[i][j]=min(dp[i][j],dp[i+1][j-1]);
else if(s[i]==s[j])
dp[i][j]=0;
dp[i][j]=min(dp[i][j],min(dp[i+1][j],dp[i][j-1])+1);
}
}
cout<<dp[0][l-1]<<endl;
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
