Banana-Leopard/TASTY huggingface dataset:
// C++ Program to find minimum number
// of manipulations required to make
// two strings identical
#include <bits/stdc++.h>
using namespace std;
 
    // Counts the no of manipulations
    // required
    int countManipulations(string s1, string s2)
    {
         
        int count = 0;
 
        // store the count of character
        int char_count[26];
         
        for (int i = 0; i < 26; i++)
        {
            char_count[i] = 0;
        }
 
        // iterate though the first String
        // and update count
        for (int i = 0; i < s1.length(); i++)
            char_count[s1[i] - 'a']++;
 
        // iterate through the second string
        // update char_count.
        // if character is not found in
        // char_count then increase count
        for (int i = 0; i < s2.length(); i++)
        {
            char_count[s2[i] - 'a']--;      
        }
       
        for(int i = 0; i < 26; ++i)
        {
          if(char_count[i] != 0)
          {
            count+=abs(char_count[i]);
          }
        }
        return count / 2;
    }
 
    // Driver code
    int main()
    {
 
        string s1 = "ddcf";
        string s2 = "cedk";
         
        cout<<countManipulations(s1, s2);
    }
  
// This code is contributed by vt_m.

Time complexity: linear
Space complexity: constant
#include <iostream>
#include <string>
using namespace std;
 
// A utility function to check if a string str is palindrome
bool isPalindrome(string str)
{
    // Start from leftmost and rightmost corners of str
    int l = 0;
    int h = str.length() - 1;
 
    // Keep comparing characters while they are same
    while (h > l)
        if (str[l++] != str[h--])
            return false;
 
    // If we reach here, then all characters were matching
    return true;
}
 
// Function to check if a given string is a rotation of a
// palindrome.
bool isRotationOfPalindrome(string str)
{
    // If string itself is palindrome
    if (isPalindrome(str))
        return true;
 
    // Now try all rotations one by one
    int n = str.length();
    for (int i = 0; i < n - 1; i++) {
        string str1 = str.substr(i + 1, n - i - 1);
        string str2 = str.substr(0, i + 1);
 
        // Check if this rotation is palindrome
        if (isPalindrome(str1.append(str2)))
            return true;
    }
    return false;
}
 
// Driver program to test above function
int main()
{
    cout << isRotationOfPalindrome("aab") << endl;
    cout << isRotationOfPalindrome("abcde") << endl;
    cout << isRotationOfPalindrome("aaaad") << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: linear
#include<iostream>
using namespace std;
  
// A function to check if n is palindrome
int isPalindrome(int n)
{
    // Find reverse of n
    int rev = 0;
    for (int i = n; i > 0; i /= 10)
        rev = rev*10 + i%10;
  
    // If n and rev are same, then n is palindrome
    return (n==rev);
}
  
// prints palindrome between min and max
void countPal(int min, int max)
{
    for (int i = min; i <= max; i++)
        if (isPalindrome(i))
          cout << i << " ";
}
  
// Driver program to test above function
int main()
{
    countPal(100, 2000);
    return 0;
}

Time complexity: logn
Space complexity: constant
// A Dynamic Programming based program to find
// minimum number insertions needed to make a
// string palindrome
#include <bits/stdc++.h>
using namespace std;
 
 
// A DP function to find minimum
// number of insertions
int findMinInsertionsDP(char str[], int n)
{
    // Create a table of size n*n. table[i][j]
    // will store minimum number of insertions
    // needed to convert str[i..j] to a palindrome.
    int table[n][n], l, h, gap;
 
    // Initialize all table entries as 0
    memset(table, 0, sizeof(table));
 
    // Fill the table
    for (gap = 1; gap < n; ++gap)
        for (l = 0, h = gap; h < n; ++l, ++h)
            table[l][h] = (str[l] == str[h])?
                        table[l + 1][h - 1] :
                        (min(table[l][h - 1],
                             table[l + 1][h]) + 1);
 
    // Return minimum number of insertions
    // for str[0..n-1]
    return table[0][n - 1];
}
 
// Driver Code
int main()
{
    char str[] = "geeks";
    cout << findMinInsertionsDP(str, strlen(str));
    return 0;
}
 
// This is code is contributed by rathbhupendra

Time complexity: quadratic
Space complexity: quadratic
// An LCS based program to find minimum number
// insertions needed to make a string palindrome
#include <bits/stdc++.h>
using namespace std;
  
 
// Returns length of LCS for X[0..m-1], Y[0..n-1].
int lcs( string X, string Y, int m, int n )
{
    int L[m+1][n+1];
    int i, j;
     
    /* Following steps build L[m+1][n+1] in bottom
        up fashion. Note that L[i][j] contains length
        of LCS of X[0..i-1] and Y[0..j-1] */
    for (i = 0; i <= m; i++)
    {
        for (j = 0; j <= n; j++)
        {
        if (i == 0 || j == 0)
            L[i][j] = 0;
     
        else if (X[i - 1] == Y[j - 1])
            L[i][j] = L[i - 1][j - 1] + 1;
     
        else
            L[i][j] = max(L[i - 1][j], L[i][j - 1]);
        }
    }
     
    /* L[m][n] contains length of LCS for X[0..n-1]
        and Y[0..m-1] */
    return L[m][n];
}
 
void reverseStr(string& str)
{
    int n = str.length();
 
    // Swap character starting from two
    // corners
    for (int i = 0; i < n / 2; i++)
        swap(str[i], str[n - i - 1]);
}
 
// LCS based function to find minimum number of
// insertions
int findMinInsertionsLCS(string str, int n)
{
    // Creata another string to store reverse of 'str'
    string rev = "";
    rev = str;
    reverseStr(rev);
     
    // The output is length of string minus length of lcs of
    // str and it reverse
    return (n - lcs(str, rev, n, n));
}
 
// Driver code
int main()
{
    string str = "geeks";
    cout << findMinInsertionsLCS(str, str.length());
    return 0;
}
 
// This code is contributed by rathbhupendra

Time complexity: quadratic
Space complexity: quadratic
// An LCS based program to find minimum number
// insertions needed to make a string palindrome
#include <bits/stdc++.h>
using namespace std;
 
// Returns length of LCS for X[0..m-1], Y[0..n-1].
int lcs(string X, string Y, int m, int n)
{
    vector<int> prev(n + 1, 0), curr(n + 1, 0);
    int i, j;
 
    for (i = 0; i <= m; i++) {
        for (j = 0; j <= n; j++) {
            if (i == 0 || j == 0)
                prev[j] = 0;
 
            else if (X[i - 1] == Y[j - 1])
                curr[j] = prev[j - 1] + 1;
 
            else
                curr[j] = max(prev[j], curr[j - 1]);
        }
       
        prev = curr;
    }
 
    /* L[m][n] contains length of LCS for X[0..n-1]
            and Y[0..m-1] */
    return prev[n];
}
 
void reverseStr(string& str)
{
    int n = str.length();
 
    // Swap character starting from two
    // corners
    for (int i = 0; i < n / 2; i++)
        swap(str[i], str[n - i - 1]);
}
 
// LCS based function to find minimum number of
// insertions
int findMinInsertionsLCS(string str, int n)
{
    // Creata another string to store reverse of 'str'
    string rev = "";
    rev = str;
    reverseStr(rev);
 
    // The output is length of string minus length of lcs of
    // str and it reverse
    return (n - lcs(str, rev, n, n));
}
 
// Driver code
int main()
{
    string str = "geeks";
    cout << findMinInsertionsLCS(str, str.length());
    return 0;
}
 
// This code is contributed by Sanskar

Time complexity: quadratic
Space complexity: linear
// A O(n^2) time and O(1) space program to
// find the longest palindromic substring
// easy to understand as compared to previous version.
  
#include <bits/stdc++.h>
using namespace std;
  
int maxLength; // variables to store and
string res; // update  maxLength and res
  
// A utility function to get the longest palindrome
// starting and expanding out from given center indices
void cSubUtil(string& s, int l, int r)
{
    // check if the indices lie in the range of string
    // and also if it is palindrome
    while (l >= 0 && r < s.length() && s[l] == s[r]) {
        // expand the boundary
        l--;
        r++;
    }
    // if it's length is greater than maxLength update
    // maxLength and res
    if (r - l - 1 >= maxLength) {
        res = s.substr(l + 1, r - l - 1);
        maxLength = r - l - 1;
    }
    return;
}
// A function which takes a string prints the LPS and
// returns the length of LPS
int longestPalSubstr(string str)
{
    res = "";
    maxLength = 1;
    // for every index in the string check palindromes
    // starting from that index
    for (int i = 0; i < str.length(); i++) {
        // check for odd length palindromes
        cSubUtil(str, i, i);
        // check for even length palindromes
        cSubUtil(str, i, i + 1);
    }
  
    cout << "Longest palindrome substring is: ";
    cout << res << "\n";
  
    return maxLength;
}
  
// Driver program to test above functions
int main()
{
    string str = "forgeeksskeegfor";
    cout << "\nLength is: " << longestPalSubstr(str)
         << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// c++ program to Count number of ways we
// can get palindrome string from a given
// string
#include<bits/stdc++.h>
using namespace std;
 
// function to find the substring of the
// string
string substring(string s,int a,int b)
{
    string s1="";
     
    // extract the specified position of
    // the string
    for(int i = a; i < b; i++)
        s1 = s1 + s[i];
         
    return s1;
}
 
// can get palindrome string from a
// given string
vector<string> allPalindromeSubstring(string s)
{
    vector<string> v ;
 
    // moving the pivot from starting till
    // end of the string
    for (float pivot = 0; pivot < s.length();
                                 pivot += .5)
    {
 
        // set radius to the first nearest
        // element on left and right
        float palindromeRadius = pivot -
                                  (int)pivot;
 
        // if the position needs to be
        // compared has an element and the
        // characters at left and right
        // matches
        while ((pivot + palindromeRadius)
         < s.length() && (pivot - palindromeRadius)
         >= 0 && s[((int)(pivot - palindromeRadius))]
             == s[((int)(pivot + palindromeRadius))])
        {
 
            v.push_back(substring(s,(int)(pivot -
                     palindromeRadius), (int)(pivot
                           + palindromeRadius + 1)));
 
            // increasing the radius by 1 to point
            // to the next elements in left and right
            palindromeRadius++;
        }
    }
 
    return v;
}
 
// Driver code
int main()
{
    vector <string> v =
                  allPalindromeSubstring("hellolle");
                   
    cout << v.size() << endl;
    for(int i = 0; i < v.size(); i++)
        cout << v[i] << ",";
    cout << endl;
    v = allPalindromeSubstring("geeksforgeeks");
    cout << v.size() << endl;
     
    for(int i = 0; i < v.size(); i++)
        cout << v[i] << ",";
}
 
// This code is contributed by Arnab Kundu.

Time complexity: cubic
Space complexity: linear
// C++ program to print all palindromic partitions
// of a given string.
#include <bits/stdc++.h>
using namespace std;
 
// Returns true if str is palindrome, else false
bool checkPalindrome(string str)
{
    int len = str.length();
    len--;
    for (int i=0; i<len; i++)
    {
        if (str[i] != str[len])
            return false;
        len--;
    }
    return true;
}
 
void printSolution(vector<vector<string> > partitions)
{
    for (int i = 0; i < partitions.size(); ++i)
    {
        for(int j = 0; j < partitions[i].size(); ++j)
            cout << partitions[i][j] << " ";
        cout << endl;
    }
    return;
}
 
// Goes through all indexes and recursively add remaining
// partitions if current string is palindrome.
void addStrings(vector<vector<string> > &v, string &s,
                vector<string> &temp, int index)
{
    int len = s.length();
    string str;
    vector<string> current = temp;
    if (index == 0)
        temp.clear();
    for (int i = index; i < len; ++i)
    {
        str = str + s[i];
        if (checkPalindrome(str))
        {
            temp.push_back(str);
            if (i+1 < len)
                addStrings(v,s,temp,i+1);
            else
                v.push_back(temp);
            temp = current;
        }
    }
    return;
}
 
// Generates all palindromic partitions of 's' and
// stores the result in 'v'.
void partition(string s, vector<vector<string> >&v)
{
    vector<string> temp;
    addStrings(v, s, temp, 0);
    printSolution(v);
    return;
}
 
// Driver code
int main()
{
    string s = "geeks";
    vector<vector<string> > partitions;
    partition(s, partitions);
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// Counts Palindromic Subsequence in a given String
#include <cstring>
#include <iostream>
using namespace std;
 
// Function return the total palindromic subsequence
int countPS(string str)
{
    int N = str.length();
 
    // create a 2D array to store the count of palindromic
    // subsequence
    int cps[N + 1][N + 1];
    memset(cps, 0, sizeof(cps));
 
    // palindromic subsequence of length 1
    for (int i = 0; i < N; i++)
        cps[i][i] = 1;
 
    // check subsequence of length L is palindrome or not
    for (int L = 2; L <= N; L++) {
        for (int i = 0; i <= N-L; i++) {
            int k = L + i - 1;
            if (str[i] == str[k])
                cps[i][k]
                    = cps[i][k - 1] + cps[i + 1][k] + 1;
            else
                cps[i][k] = cps[i][k - 1] + cps[i + 1][k]
                            - cps[i + 1][k - 1];
        }
    }
 
    // return total palindromic subsequence
    return cps[0][N - 1];
}
 
// Driver program
int main()
{
    string str = "abcb";
    cout << "Total palindromic subsequence are : "
         << countPS(str) << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// C++ program to counts Palindromic Subsequence
// in a given String using recursion
#include <bits/stdc++.h>
using namespace std;
 
int n, dp[1000][1000];
string str = "abcb";
 
// Function return the total
// palindromic subsequence
int countPS(int i, int j)
{
 
    if (i > j)
        return 0;
 
    if (dp[i][j] != -1)
        return dp[i][j];
 
    if (i == j)
        return dp[i][j] = 1;
 
    else if (str[i] == str[j])
        return dp[i][j]
               = countPS(i + 1, j) +
                countPS(i, j - 1) + 1;
 
    else
        return dp[i][j] = countPS(i + 1, j) +
                          countPS(i, j - 1) -
                          countPS(i + 1, j - 1);
}
 
// Driver code
int main()
{
    memset(dp, -1, sizeof(dp));
    n = str.size();
    cout << "Total palindromic subsequence are : "
         << countPS(0, n - 1) << endl;
    return 0;
}
// this code is contributed by Kushdeep Mittal

Time complexity: quadratic
Space complexity: quadratic
// C++ program for getting minimum character to be
// added at front to make string palindrome
#include<bits/stdc++.h>
using namespace std;
 
// function for checking string is palindrome or not
bool ispalindrome(string s)
{
    int l = s.length();
    int j;
     
    for(int i = 0, j = l - 1; i <= j; i++, j--)
    {
        if(s[i] != s[j])
            return false;
    }
    return true;
}
 
// Driver code
int main()
{
    string s = "BABABAA";
    int cnt = 0;
    int flag = 0;
     
    while(s.length()>0)
    {
        // if string becomes palindrome then break
        if(ispalindrome(s))
        {
            flag = 1;
             break;
        }
        else
        {
        cnt++;
         
        // erase the last element of the string
        s.erase(s.begin() + s.length() - 1);
        }
    }
     
    // print the number of insertion at front
    if(flag)
        cout << cnt;
}

Time complexity: quadratic
Space complexity: constant
// C++ program for getting minimum character to be
// added at front to make string palindrome
#include <bits/stdc++.h>
using namespace std;
 
// returns vector lps for given string str
vector<int> computeLPSArray(string str)
{
    int M = str.length();
    vector<int> lps(M);
 
    int len = 0;
    lps[0] = 0; // lps[0] is always 0
 
    // the loop calculates lps[i] for i = 1 to M-1
    int i = 1;
    while (i < M)
    {
        if (str[i] == str[len])
        {
            len++;
            lps[i] = len;
            i++;
        }
        else // (str[i] != str[len])
        {
            // This is tricky. Consider the example.
            // AAACAAAA and i = 7. The idea is similar
            // to search step.
            if (len != 0)
            {
                len = lps[len-1];
 
                // Also, note that we do not increment
                // i here
            }
            else // if (len == 0)
            {
                lps[i] = 0;
                i++;
            }
        }
    }
    return lps;
}
 
// Method returns minimum character to be added at
// front to make string palindrome
int getMinCharToAddedToMakeStringPalin(string str)
{
    string revStr = str;
    reverse(revStr.begin(), revStr.end());
 
    // Get concatenation of string, special character
    // and reverse string
    string concat = str + "$" + revStr;
 
    //  Get LPS array of this concatenated string
    vector<int> lps = computeLPSArray(concat);
 
    // By subtracting last entry of lps vector from
    // string length, we will get our result
    return (str.length() - lps.back());
}
 
// Driver program to test above functions
int main()
{
    string str = "AACECAAAA";
    cout << getMinCharToAddedToMakeStringPalin(str);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to get largest palindrome changing
// atmost K digits
#include <bits/stdc++.h>
using namespace std;
 
// Returns maximum possible
// palindrome using k changes
string maximumPalinUsingKChanges(string str, int k)
{
    string palin = str;
 
    // Initialize l and r by leftmost and
    // rightmost ends
    int l = 0;
    int r = str.length() - 1;
 
    //  first try to make string palindrome
    while (l < r) {
       
        // Replace left and right character by
        // maximum of both
        if (str[l] != str[r]) {
            palin[l] = palin[r] =
                  max(str[l], str[r]);
            k--;
        }
        l++;
        r--;
    }
 
    // If k is negative then we can't make
    // string palindrome
    if (k < 0)
        return "Not possible";
 
    l = 0;
    r = str.length() - 1;
 
    while (l <= r) {
       
        // At mid character, if K>0 then change
        // it to 9
        if (l == r) {
            if (k > 0)
                palin[l] = '9';
        }
 
        // If character at lth (same as rth) is
        // less than 9
        if (palin[l] < '9') {
            /* If none of them is changed in the
               previous loop then subtract 2 from K
               and convert both to 9 */
            if (k >= 2 && palin[l] == str[l]
                && palin[r] == str[r]) {
                k -= 2;
                palin[l] = palin[r] = '9';
            }
 
            /*  If one of them is changed
                in the previous
                loop then subtract 1 from K
                (1 more is
                subtracted already) and make them 9  */
            else if (k >= 1
                     && (palin[l] != str[l]
                         || palin[r] != str[r])) {
                k--;
                palin[l] = palin[r] = '9';
            }
        }
        l++;
        r--;
    }
 
    return palin;
}
 
//  Driver code to test above methods
int main()
{
    string str = "43435";
    int k = 3;
    cout << maximumPalinUsingKChanges(str, k);
    return 0;
}

Time complexity: linear
Space complexity: linear
// A recursive C++ program to
// check whether a given number
// is palindrome or not
#include <bits/stdc++.h>
using namespace std;
 
// A recursive function that
// check a str[s..e] is
// palindrome or not.
bool isPalRec(char str[],
              int s, int e)
{
     
    // If there is only one character
    if (s == e)
    return true;
 
    // If first and last
    // characters do not match
    if (str[s] != str[e])
    return false;
 
    // If there are more than
    // two characters, check if
    // middle substring is also
    // palindrome or not.
    if (s < e + 1)
    return isPalRec(str, s + 1, e - 1);
 
    return true;
}
 
bool isPalindrome(char str[])
{
    int n = strlen(str);
     
    // An empty string is
    // considered as palindrome
    if (n == 0)
        return true;
     
    return isPalRec(str, 0, n - 1);
}
 
// Driver Code
int main()
{
    char str[] = "geeg";
 
    if (isPalindrome(str))
    cout << "Yes";
    else
    cout << "No";
 
    return 0;
}
 
// This code is contributed by shivanisinghss2110

Time complexity: linear
Space complexity: linear
#include <iostream>
using namespace std;
 
bool isPalindrome(string s, int i){
        
    if(i > s.size()/2){
       return true ;
    }
    
    return s[i] == s[s.size()-i-1] && isPalindrome(s, i+1) ;
    
}
     
     
int main()
{
    string str = "geeg" ;
    if (isPalindrome(str, 0))
    cout << "Yes";
    else
    cout << "No";
 
    return 0;
 
}

Time complexity: linear
Space complexity: linear
// C++ implementation to find maximum length
// substring which is not palindrome
#include <bits/stdc++.h>
using namespace std;
 
// utility function to check whether
// a string is palindrome or not
bool isPalindrome(string str)
{
    // Check for palindrome.
    int n = str.size();
    for (int i=0; i < n/2; i++)
        if (str.at(i) != str.at(n-i-1))
            return false;
 
    // palindrome string
    return true;
}
 
// function to find maximum length
// substring which is not palindrome
int maxLengthNonPalinSubstring(string str)
{
    int n = str.size();
    char ch = str.at(0);
 
    // to check whether all characters
    // of the string are same or not
    int i = 1;
    for (i=1; i<n; i++)
        if (str.at(i) != ch)
            break;
 
    // All characters are same, we can't
    // make a non-palindromic string.
    if (i == n)
        return 0;
 
    // If string is palindrome, we can make
    // it non-palindrome by removing any
    // corner character
    if (isPalindrome(str))
        return n-1;
 
    // Complete string is not a palindrome.
    return n;
}
 
// Driver program to test above
int main()
{
    string str = "abba";
    cout << "Maximum length = "
         << maxLengthNonPalinSubstring(str);
    return 0;
}

Time complexity: linear
Space complexity: linear
//  C++ program to find minimum step to delete a string
#include <bits/stdc++.h>
using namespace std;
 
/* method returns minimum step for deleting the string,
   where in one step a palindrome is removed */
int helper(string str, int si, int ei,
           vector<vector<int> >& dp)
{
 
    // if the string is empty
    // need no operation
    if (si > ei)
        return 0;
 
    // string length one
    // need one operation
    if (ei - si + 1 == 1)
        return 1;
 
    // if already calculated
    if (dp[si][ei] != -1)
        return dp[si][ei];
 
    // to consider three options
    int op1 = 1e9, op2 = 1e9, op3 = 1e9;
 
    // delete first char and call
    // on the smaller subproblem
    op1 = 1 + helper(str, si + 1, ei, dp);
 
    // first two characters are same
    if (str[si] == str[si + 1])
        op2 = 1 + helper(str, si + 2, ei, dp);
 
    // found another index where the
    // character is same as si-th character
    for (int i = si + 2; i <= ei; i++) {
        if (str[si] == str[i])
            op3 = min(op3,
                      helper(str, si + 1, i - 1, dp)
                          + helper(str, i + 1, ei, dp));
    }
 
    // return the minimum b/w three options
    return dp[si][ei] = min({ op1, op2, op3 });
}
 
int minStepToDeleteString(string s)
{
    int n = s.size();
 
    // dp table to remove repeatations
    vector<vector<int> > dp(n, vector<int>(n, -1));
 
    // passing starting and ending index
    return helper(s, 0, n - 1, dp);
}
 
// Driver Code
int main()
{
    string str = "2553432";
    cout << minStepToDeleteString(str) << endl;
    return 0;
}
 
// this code is contributed by rajdeep999

Time complexity: quadratic
Space complexity: quadratic