Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ex. 11.35 Dynamic progi Let Charl ..n) be an array of n characters longest seque

ID: 3733742 • Letter: E

Question

Ex. 11.35 Dynamic progi Let Charl ..n) be an array of n characters longest sequeno em is Find the longest sequence of characters S where there isa same as S (and in the same sa Subse not necessarily consecutive characters in Char that are the there is a subsequence of not necessarily consecutive characters in Char that are the sam der) and1 S (and in the same order). The two subsequences in Char do not have to be the same recursive specification that computes the length of such a longest look both ways subse data Char 1..) a) The look both ways problem is: same as the reverse the same. As wite b Find the longest subsequence of not necessarily consecutive characters in Char th palindrome is a sequence S that is the same as its reverse. For example, the f palindrome, as is the 21-letter phrase A man, a plan, a canal, Panama. (it is customary to i ignore spax write a recursive so punctuation, and capitalization when declaring phrases palindromes,) As always, you are to specification that computes the length of the solution. d In what ways are a and b different problems d) Present a sequence X of five characters (with three difrent letters) that contains a string S and Serned Ex. eversed Let

Explanation / Answer

#include <bits/stdc++.h>

#define MAX_CHAR 256

using namespace std;

bool isPalindrome(char str[], int l, int h)

{

    while (h > l)

        if (str[l++] != str[h--])

            return false;

    return true;

}

int check(char str[])

{

    int n = strlen(str);

  

    int freq[MAX_CHAR] = { 0 };

  

    for (int i = 0; i < n; i++)

    {

        freq[str[i]]++;

  

        if (freq[str[i]] > 3)

            return true;

    }

  

    int k = 0;

    for (int i = 0; i < n; i++)

        if (freq[str[i]] > 1)

            str[k++] = str[i];

    str[k] = '';

if (isPalindrome(str, 0, k-1))

    {

  

        if (k & 1)

            return str[k/2] == str[k/2 - 1];

return false;

    }

return true;

}

int main()

{

    char str[] = "ABCABD";

    if (check(str))

        cout << "Repeated Subsequence Exists";

    else

        cout << "Repeated Subsequence Doesn't Exists";

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote