Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
2,144 views
in Online Assessments by Expert (115,770 points) 1 flag | 2,144 views

4 Answers

0 like 0 dislike
// The Difference

#include <bits/stdc++.h>

using namespace std;

int LPS(string str, int n)

{

    int longest_p = 1;

    vector<vector<int>> dp(n, vector<int>(n, 0));

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

    {

        for (int i = 0, j = g; j < n; i++, j++)

        {

            if (g == 0)

                dp[i][j] = 1;

            else if (g == 1)

            {

                if (str[i] == str[j])

                {

                    dp[i][j] = 1;

                    longest_p = max(longest_p, j - i + 1);

                }

            }

            else

            {

                if (str[i] == str[j] && dp[i + 1][j - 1])

                {

                    dp[i][j] = 1;

                    longest_p = max(longest_p, j - i + 1);

                }

            }

        }

    }

    return longest_p;

}

int main()

{

    string str;

    cin >> str;

    int n = str.size();

    if (n == 0 || n == 1)

        cout << 0 << endl;

    else

        cout << LPS(str, n) - 1 << endl;

    return 0;

}
by (300 points)
0 like 0 dislike
// Passwords Problem

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    cin >> n;

    vector<string> passwords(n, "");

    unordered_map<string, int> pw_check;

 

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

    {

        cin >> passwords[i];

    }

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

    {

        string even_char = "", odd_char = "";

        for (int j = 0; j < passwords[i].size(); j++)

        {

            if (j % 2 == 0)

                even_char += passwords[i][j];

            else

                odd_char += passwords[i][j];

        }

        sort(even_char.begin(), even_char.end());

        sort(odd_char.begin(), odd_char.end());

        string hash_string = even_char + '#' + odd_char;

        pw_check[hash_string]++;

    }

    cout << pw_check.size() << endl;

    return 0;

}
by (300 points)
0 like 0 dislike

Question asked : 

image

by Expert (115,770 points)
0 like 0 dislike

Question asked : 

 

image

by Expert (115,770 points)