Banana-Leopard/TASTY huggingface dataset:
// C++ program for printing sentence
// without repetitive vowels
#include <bits/stdc++.h>
using namespace std;
 
// function which returns True or False
// for occurrence of a vowel
bool is_vow(char c)
{
    // this compares vowel with
    // character 'c'
    return (c == 'a') || (c == 'e') ||
           (c == 'i') || (c == 'o') ||
           (c == 'u');
}
 
// function to print resultant string
void removeVowels(string str)
{
    // print 1st character
    printf("%c", str[0]);
 
    // loop to check for each character
    for (int i = 1; str[i]; i++)
 
        // comparison of consecutive characters
        if ((!is_vow(str[i - 1])) ||
            (!is_vow(str[i])))
            printf("%c", str[i]);
}
 
// Driver Code
int main()
{
    char str[] = " geeks for geeks";
    removeVowels(str);
}
 
// This code is contributed by Abhinav96

Time complexity: linear
Space complexity: linear
// C++ program to count vowels in a string
#include<iostream>
using namespace std;
 
// Function to check the Vowel
bool isVowel(char ch)
{
    ch = toupper(ch);
    return (ch=='A' || ch=='E' || ch=='I' ||
                       ch=='O' || ch=='U');
}
 
// Returns count of vowels in str
int countVowels(string str)
{
    int count = 0;
    for (int i=0; i<str.length(); i++)
        if (isVowel(str[i])) // Check for vowel
            ++count;
    return count;
}
 
// Main Calling Function
int main()
{
    //string object
    string str = "abc de";
 
    // Total numbers of Vowel
    cout << countVowels(str) << endl;
    return 0;
}

Time complexity: linear
Space complexity: constant
// Recursive C++ program to count the total
// number of vowels using recursion
#include<iostream>
using namespace std;
 
// Function to check the Vowel
bool isVowel(char ch)
{
    ch = toupper(ch);
    return (ch=='A' || ch=='E' || ch=='I' ||
                        ch=='O' || ch=='U');
}
 
// to count total number of vowel from 0 to n
int countVovels(string str, int n)
{
    if (n == 1)
        return isVowel(str[n-1]);
 
    return countVovels(str, n-1) + isVowel(str[n-1]);
}
 
// Main Calling Function
int main()
{
    // string object
    string str = "abc de";
 
    // Total numbers of Vowel
    cout << countVovels(str, str.length()) << endl;
    return 0;
}

Time complexity: linear
Space complexity: linear
// Iterative CPP program to count total number
// of consonants
#include <iostream>
using namespace std;
 
// Function to check for consonant
bool isConsonant(char ch)
{
    // To handle lower case
    ch = toupper(ch);
 
    return !(ch == 'A' || ch == 'E' ||
            ch == 'I' || ch == 'O' ||
            ch == 'U') && ch >= 65 && ch <= 90;
}
 
int totalConsonants(string str)
{
    int count = 0;
    for (int i = 0; i < str.length(); i++)
 
        // To check is character is Consonant
        if (isConsonant(str[i]))
            ++count;
    return count;
}
 
// Driver code
int main()
{
    string str = "abc de";
    cout << totalConsonants(str);
    return 0;
}

Time complexity: linear
Space complexity: constant
// Recursive CPP program to count total number
// of consonants
#include <iostream>
using namespace std;
 
// Function to check for consonant
bool isConsonant(char ch)
{
    // To handle lower case
    ch = toupper(ch);
 
    return !(ch == 'A' || ch == 'E' ||
            ch == 'I' || ch == 'O' ||
            ch == 'U') && ch >= 65 && ch <= 90;
}
 
// to count total number of consonants from
// 0 to n-1
int totalConsonants(string str, int n)
{
    if (n == 1)
        return isConsonant(str[0]);
 
    return totalConsonants(str, n - 1) +
           isConsonant(str[n-1]);
}
 
// Driver code
int main()
{
    string str = "abc de";
    cout << totalConsonants(str, str.length());
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to find number of distinct
// permutations of a string.
#include<bits/stdc++.h>
using namespace std;
const int MAX_CHAR = 26;
 
// Utility function to find factorial of n.
int factorial(int n)
{
    int fact = 1;
    for (int i = 2; i <= n; i++)
        fact = fact * i;
    return fact;
}
 
// Returns count of distinct permutations
// of str.
int countDistinctPermutations(string str)
{
    int length = str.length();
 
    int freq[MAX_CHAR];
    memset(freq, 0, sizeof(freq));
 
    // finding frequency of all the lower case
    // alphabet and storing them in array of
    // integer
    for (int i = 0; i < length; i++)
        if (str[i] >= 'a')
            freq[str[i] - 'a']++;
 
    // finding factorial of number of appearances
    // and multiplying them since they are
    // repeating alphabets
    int fact = 1;
    for (int i = 0; i < MAX_CHAR; i++)
        fact = fact * factorial(freq[i]);
 
    // finding factorial of size of string and
    // dividing it by factorial found after
    // multiplying
    return factorial(length) / fact;
}
 
// Driver code
int main()
{
    string str = "fvvfhvgv";
    printf("%d", countDistinctPermutations(str));
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to print all permutations with
// duplicates allowed using rotate() in STL
#include <bits/stdc++.h>
using namespace std;
 
// Function to print permutations of string str,
// out is used to store permutations one by one
void permute(string str, string out)
{
    // When size of str becomes 0, out has a
    // permutation (length of out is n)
    if (str.size() == 0)
    {
        cout << out << endl;
        return;
    }
 
    // One be one move all characters at
    // the beginning of out (or result)
    for (int i = 0; i < str.size(); i++)
    {
        // Remove first character from str and
        // add it to out
        permute(str.substr(1), out + str[0]);
 
        // Rotate string in a way second character
        // moves to the beginning.
        rotate(str.begin(), str.begin() + 1, str.end());
    }
}
 
// Driver code
int main()
{
    string str = "ABC";
    permute(str, "");
    return 0;
}

Time complexity: np
Space complexity: linear
// C++ program to print all permutations with
// duplicates allowed using next_permutation
#include <bits/stdc++.h>
using namespace std;
 
// Function to print permutations of string str
// using next_permutation
void permute(string str)
{
    // Sort the string in lexicographically
    // ascending order
    sort(str.begin(), str.end());
 
    // Keep printing next permutation while there
    // is next permutation
    do {
       cout << str << endl;
    } while (next_permutation(str.begin(), str.end()));
}
 
// Driver code
int main()
{
    string str = "CBA";
    permute(str);
    return 0;
}

Time complexity: np
Space complexity: constant
// C++ program to check if it is
// possible to split string or not
#include <bits/stdc++.h>
using namespace std;
const int MAX_CHAR = 26;
 
// function to check if we can split
// string or not
bool checkCorrectOrNot(string s)
{
    // Counter array initialized with 0
    int count1[MAX_CHAR] = {0};
    int count2[MAX_CHAR] = {0};
 
    // Length of the string
    int n = s.length();
    if (n == 1)
        return true;
 
    // traverse till the middle element
    // is reached
    for (int i=0,j=n-1; i<j; i++,j--)
    {
        // First half
        count1[s[i]-'a']++;
 
        // Second half
        count2[s[j]-'a']++;
    }
 
    // Checking if values are different
    // set flag to 1
    for (int i = 0; i<MAX_CHAR; i++)
        if (count1[i] != count2[i])
            return false;
 
    return true;
}
 
// Driver program to test above function
int main()
{
    // String to be checked
    string s = "abab";
 
    if (checkCorrectOrNot(s))
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to check if it is
// possible to split string or not
#include <bits/stdc++.h>
using namespace std;
const int MAX_CHAR = 26;
 
// function to check if we can split
// string or not
bool checkCorrectOrNot(string s)
{
    // Counter array initialized with 0
    int count[MAX_CHAR] = {0};
 
    // Length of the string
    int n = s.length();
    if (n == 1)
        return true;
 
    // traverse till the middle element
    // is reached
    for (int i=0,j=n-1; i<j; i++,j--)
    {
        // First half
        count[s[i]-'a']++;
 
        // Second half
        count[s[j]-'a']--;
    }
 
    // Checking if values are different
    // set flag to 1
    for (int i = 0; i<MAX_CHAR; i++)
        if (count[i] != 0)
            return false;
 
    return true;
}
 
// Driver program to test above function
int main()
{
    // String to be checked
    string s = "abab";
 
    if (checkCorrectOrNot(s))
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ implementation to find the character in
// first string that is present at minimum index
// in second string
#include <bits/stdc++.h>
using namespace std;
 
// function to find the minimum index character
void printMinIndexChar(string str, string patt)
{
    // to store the index of character having
    // minimum index
    int minIndex = INT_MAX;
 
    // lengths of the two strings
    int m = str.size();
    int n = patt.size();
 
    // traverse 'patt'
    for (int i = 0; i < n; i++) {
 
        // for each character of 'patt' traverse 'str'
        for (int j = 0; j < m; j++) {
 
            // if patt[i] is found in 'str', check if
            // it has the minimum index or not. If yes,
            // then update 'minIndex' and break
            if (patt[i] == str[j] && j < minIndex) {
                minIndex = j;
                break;
            }
        }
    }
 
    // print the minimum index character
    if (minIndex != INT_MAX)
        cout << "Minimum Index Character = "
             << str[minIndex];
 
    // if no character of 'patt' is present in 'str'
    else
        cout << "No character present";
}
 
// Driver program to test above
int main()
{
    string str = "geeksforgeeks";
    string patt = "set";
    printMinIndexChar(str, patt);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ implementation to find the character in first
// string that is present at minimum index in second
// string
#include <bits/stdc++.h>
using namespace std;
 
// function to find the minimum index character
void printMinIndexChar(string str, string patt)
{
    // unordered_map 'um' implemented as hash table
    unordered_map<char, int> um;
 
    // to store the index of character having
    // minimum index
    int minIndex = INT_MAX;
 
    // lengths of the two strings
    int m = str.size();
    int n = patt.size();
 
    // store the first index of each character of 'str'
    for (int i = 0; i < m; i++) {
        if (um.find(str[i]) == um.end())
            um[str[i]] = i;
    }
    // traverse the string 'patt'
    for (int j = 0; j < n; j++) {
 
        // if patt[i] is found in 'um', check if
        // it has the minimum index or not accordingly
        // update 'minIndex'
        if (um.find(patt[j]) != um.end()
            && um[patt[j]] < minIndex)
            minIndex = um[patt[j]];
    }
    // print the minimum index character
    if (minIndex != INT_MAX)
        cout << "Minimum Index Character = "
             << str[minIndex];
 
    // if no character of 'patt' is present in 'str'
    else
        cout << "No character present";
}
 
// Driver program to test above
int main()
{
    string str = "geeksforgeeks";
    string patt = "set";
    printMinIndexChar(str, patt);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ implementation of program to find the maximum length
// that can be removed
#include<bits/stdc++.h>
using namespace std;
 
// Function to find the length of longest sub-string that
// can me make removed
// arr  --> pair type of array whose first field store
//          character in string and second field stores
//          corresponding index of that character
int longestNull(string str)
{
    vector<pair<char,int> > arr;
 
    // store {'@',-1} in arr , here this value will
    // work as base index
    arr.push_back({'@', -1});
 
    int maxlen = 0;   // Initialize result
 
    // one by one iterate characters of string
    for (int i = 0; i < str.length(); ++i)
    {
        // make pair of char and index , then store
        // them into arr
        arr.push_back({str[i], i});
 
        // now if last three elements of arr[]  are making
        // sub-string "100" or not
        while (arr.size()>=3 &&
               arr[arr.size()-3].first=='1' &&
               arr[arr.size()-2].first=='0' &&
               arr[arr.size()-1].first=='0')
        {
            // if above condition is true then delete
            // sub-string "100" from arr[]
            arr.pop_back();
            arr.pop_back();
            arr.pop_back();
        }
 
        // index of current last element in arr[]
        int tmp = arr.back().second;
 
        // This is important, here 'i' is the index of
        // current character inserted into arr[]
        // and 'tmp' is the index of last element in arr[]
        // after continuous deletion of sub-string
        // "100" from arr[] till we make it null, difference
        // of these to 'i-tmp' gives the length of current
        // sub-string that can be make null by continuous
        // deletion of sub-string "100"
        maxlen = max(maxlen, i - tmp);
    }
 
    return maxlen;
}
 
// Driver program to run the case
int main()
{
    cout << longestNull("1011100000100");
    return 0;
}

Time complexity: linear
Space complexity: linear
// CPP program to count the number of pairs
#include <bits/stdc++.h>
using namespace std;
#define MAX 256
 
// Function to count the number of equal pairs
int countPairs(string s)
{
    // Hash table
    int cnt[MAX] = { 0 };
 
    // Traverse the string and count occurrence
    for (int i = 0; i < s.length(); i++)
        cnt[s[i]]++;
 
    // Stores the answer
    int ans = 0;
 
    // Traverse and check the occurrence of every character
    for (int i = 0; i < MAX; i++)
        ans += cnt[i] * cnt[i];
 
    return ans;
}
 
// Driver Code
int main()
{
    string s = "geeksforgeeks";
    cout << countPairs(s);
    return 0;
}

Time complexity: linear
Space complexity: linear
// CPP Program to count strings with adjacent
// characters.
#include <bits/stdc++.h>
using namespace std;
 
int countStrs(int n)
{
    long int dp[n + 1][27];
 
    // Initializing arr[n+1][27] to 0
    memset(dp, 0, sizeof(dp));
 
    // Initialing 1st row all 1 from 0 to 25
    for (int i = 0; i <= 25; i++)
        dp[1][i] = 1;
 
    // Begin evaluating from i=2 since 1st row is set
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= 25; j++)
 
            // j=0 is 'A' which can make strings
            // of length i using strings of length
            // i-1 and starting with 'B'
            if (j == 0)
                dp[i][j] = dp[i - 1][j + 1];
            else
                dp[i][j] = (dp[i - 1][j - 1] +
                            dp[i - 1][j + 1]);
    }
 
    // Our result is sum of last row.
    long int sum = 0;
    for (int i = 0; i <= 25; i++)
        sum = (sum + dp[n][i]);
    return sum;
}
 
// Driver's Code
int main()
{
    int n = 3;
    cout << "Total strings are : " << countStrs(n);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to print Number of Words,
// Vowels and Frequency of Each Character
#include <bits/stdc++.h>
using namespace std;
 
void words(string str)
{
    int wcount = 0, ucount = 0, vcount = 0;
    for (int i = 0; i < str.length(); i++)
    {
        char c = str[i];
        switch (c)
        {
            case ' ':
            case '.':
            wcount++; // more delimiters can be given
        }
 
        switch (c)
        {
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
                vcount++;
        }
 
        if (c >= 65 and c <= 90) ucount++;
    }
 
    cout << "Number of words = "
         << wcount << endl;
    cout << "Number of vowels = "
         << vcount << endl;
    cout << "Number of upper case characters = "
         << ucount << endl;
}
 
// Function to calculate the frequency
// of each character in the string
void frequency(string str)
{
    // Creates an empty TreeMap
    map<char, int> hmap;
 
    // Traverse through the given array
    for (int i = 0; i < str.length(); i++)
        hmap[str[i]]++;
 
    // Print result
    for (auto i : hmap)
    {
        cout << "Character = " << i.first;
        cout << " Frequency = "
             << i.second << endl;
    }
}
 
// Driver Code
int main(int argc, char const *argv[])
{
    string str = "Geeks for Geeks.";
    words(str);
    frequency(str);
    return 0;
}
 
// This code is contributed by
// sanjeev2552

Time complexity: linear
Space complexity: constant
// C++ program to Find longest subsequence where
//  every character appears at-least k times
#include<bits/stdc++.h>
using namespace std;
 
const int MAX_CHARS = 26;
 
void longestSubseqWithK(string str, int k)   
{
    int n = str.size();                  
 
    // Count frequencies of all characters
    int freq[MAX_CHARS] = {0};                   
    for (int i = 0 ; i < n; i++)   
        freq[str[i] - 'a']++;             
     
    // Traverse given string again and print
    // all those characters whose frequency
    // is more than or equal to k.
    for (int i = 0 ; i < n ; i++)  
        if (freq[str[i] - 'a'] >= k)              
            cout << str[i];     
}
 
// Driver code
int main() {
    string str = "geeksforgeeks";
    int k = 2;
    longestSubseqWithK(str, k);      
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to Find longest subsequence where every
// character appears at-least k times
#include <bits/stdc++.h>
using namespace std;
 
void longestSubseqWithK(string str, int k)
{
    int n = str.size();
    map<char, int> mp;
 
    // Count frequencies of all characters
    for (int i = 0; i < n; i++) {
        char t = str[i];
        mp[t]++;
    }
 
    // Traverse given string again and print
    // all those characters whose frequency
    // is more than or equal to k.
    for (int i = 0; i < n; i++) {
        char t = str[i];
        if (mp[t] >= k) {
            cout << t;
        }
    }
}
 
// Driver code
int main()
{
    string str = "geeksforgeeks";
    int k = 2;
    longestSubseqWithK(str, k);
 
    return 0;
}
 
// This code is contributed by rakeshsahni

Time complexity: nlogn
Space complexity: linear
// Recursive C++ program to check
// if a string is subsequence
// of another string
#include <cstring>
#include <iostream>
using namespace std;
 
// Returns true if str1[] is a
// subsequence of str2[]. m is
// length of str1 and n is length of str2
bool isSubSequence(char str1[], char str2[], int m, int n)
{
 
    // Base Cases
    if (m == 0)
        return true;
    if (n == 0)
        return false;
 
    // If last characters of two
    // strings are matching
    if (str1[m - 1] == str2[n - 1])
        return isSubSequence(str1, str2, m - 1, n - 1);
 
    // If last characters are
    // not matching
    return isSubSequence(str1, str2, m, n - 1);
}
 
// Driver program to check whether str1 is subsequence of str2 or not.
int main()
{
    char str1[] = "gksrek";
    char str2[] = "geeksforgeeks";
    int m = strlen(str1);
    int n = strlen(str2);
    isSubSequence(str1, str2, m, n) ? cout << "Yes "
                                    : cout << "No";
    return 0;
}

Time complexity: linear
Space complexity: linear
/*Iterative C++ program to check
If a string is subsequence of another string*/
 
#include <bits/stdc++.h>
using namespace std;
 
/*Returns true if s1 is subsequence of s2*/
bool issubsequence(string& s1, string& s2)
{
    int n = s1.length(), m = s2.length();
    int i = 0, j = 0;
    while (i < n && j < m) {
        if (s1[i] == s2[j])
            i++;
        j++;
    }
    /*If i reaches end of s1,that mean we found all
    characters of s1 in s2,
    so s1 is subsequence of s2, else not*/
    return i == n;
}
int main()
 
{
    string s1 = "gksrek";
    string s2 = "geeksforgeeks";
    if (issubsequence(s1, s2))
        cout << "gksrek is subsequence of geekforgeeks" << endl;
    else
        cout << "gksrek is not a subsequence of geekforgeeks" << endl;
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to count subsequences of the
// form a^i b^j c^k
#include <bits/stdc++.h>
using namespace std;
 
// Returns count of subsequences of the form
// a^i b^j c^k
int countSubsequences(string s)
{
    // Initialize counts of different subsequences
    // caused by different combination of 'a'
    int aCount = 0;
 
    // Initialize counts of different subsequences
    // caused by different combination of 'a' and
    // different combination of 'b'
    int bCount = 0;
 
    // Initialize counts of different subsequences
    // caused by different combination of 'a', 'b'
    // and 'c'.
    int cCount = 0;
 
    // Traverse all characters of given string
    for (unsigned int i = 0; i < s.size(); i++) {
        /* If current character is 'a', then
           there are the following possibilities :
             a) Current character begins a new
                subsequence.
             b) Current character is part of aCount
                subsequences.
             c) Current character is not part of
                aCount subsequences. */
        if (s[i] == 'a')
            aCount = (1 + 2 * aCount);
 
        /* If current character is 'b', then
           there are following possibilities :
             a) Current character begins a new
                subsequence of b's with aCount
                subsequences.
             b) Current character is part of bCount
                subsequences.
             c) Current character is not part of
                bCount subsequences. */
        else if (s[i] == 'b')
            bCount = (aCount + 2 * bCount);
 
        /* If current character is 'c', then
           there are following possibilities :
             a) Current character begins a new
                subsequence of c's with bCount
                subsequences.
             b) Current character is part of cCount
                subsequences.
             c) Current character is not part of
                cCount subsequences. */
        else if (s[i] == 'c')
            cCount = (bCount + 2 * cCount);
    }
 
    return cCount;
}
 
// Driver code
int main()
{
    string s = "abbc";
    cout << countSubsequences(s) << endl;
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to count subsequences of a
// string divisible by n.
#include<bits/stdc++.h>
using namespace std;
 
// Returns count of subsequences of str
// divisible by n.
int countDivisibleSubseq(string str, int n)
{
    int len = str.length();
 
    // division by n can leave only n remainder
    // [0..n-1]. dp[i][j] indicates number of
    // subsequences in string [0..i] which leaves
    // remainder j after division by n.
    int dp[len][n];
    memset(dp, 0, sizeof(dp));
 
    // Filling value for first digit in str
    dp[0][(str[0]-'0')%n]++;
 
    for (int i=1; i<len; i++)
    {
        // start a new subsequence with index i
        dp[i][(str[i]-'0')%n]++;
 
        for (int j=0; j<n; j++)
        {
            // exclude i'th character from all the
            // current subsequences of string [0...i-1]
            dp[i][j] += dp[i-1][j];
 
            // include i'th character in all the current
            // subsequences of string [0...i-1]
            dp[i][(j*10 + (str[i]-'0'))%n] += dp[i-1][j];
        }
    }
 
    return dp[len-1][0];
}
 
// Driver code
int main()
{
    string str = "1234";
    int n = 4;
    cout << countDivisibleSubseq(str, n);
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic