Banana-Leopard/TASTY huggingface dataset:
// C++ program to split a numeric
// string in an Increasing
// sequence if possible
#include <bits/stdc++.h>
using namespace std;
 
// Function accepts a string and
// checks if string can be split.
void split(string str)
{
    int len = str.length();
 
    // if there is only 1 number
    // in the string then
    // it is not possible to split it
    if (len == 1) {
        cout << ("Not Possible");
        return;
    }
 
    string s1 = "", s2 = "";
    long num1, num2;
 
    for (int i = 0; i <= len / 2; i++) {
 
        int flag = 0;
 
        // storing the substring from
        // 0 to i+1 to form initial
        // number of the increasing sequence
        s1 = str.substr(0, i + 1);
        num1 = stoi((s1));
        num2 = num1 + 1;
 
        // convert string to integer
        // and add 1 and again convert
        // back to string s2
        s2 = to_string(num2);
        int k = i + 1;
        while (flag == 0) {
            int l = s2.length();
 
            // if s2 is not a substring
            // of number than not possible
            if (k + l > len) {
                flag = 1;
                break;
            }
 
            // if s2 is the next substring
            // of the numeric string
            if ((str.substr(k, k + l) == s2)) {
                flag = 0;
 
                // Increase num2 by 1 i.e the
                // next number to be looked for
                num2++;
                k = k + l;
 
                // check if string is fully
                // traversed then break
                if (k == len)
                    break;
                s2 = to_string(num2);
                l = s2.length();
                if (k + 1 > len) {
 
                    // If next string doesnot occurs
                    // in a given numeric string
                    // then it is not possible
                    flag = 1;
                    break;
                }
            }
 
            else
                flag = 1;
        }
 
        // if the string was fully traversed
        // and conditions were satisfied
        if (flag == 0) {
            cout << "Possible " << s1 << endl;
            break;
        }
 
        // if conditions failed to hold
        else if (flag == 1 && i > len / 2 - 1) {
            cout << "Not Possible" << endl;
            break;
        }
    }
}
   
// Driver code
int main()
{
    string str = "99100";
   
    // Call the split function
    // for splitting the string
    split(str);
 
    return 0;
}
 
// This code is contributed by divyeshrabadiya07

Time complexity: quadratic
Space complexity: linear
// CPP Program to find number of way
// to split string such that each partition
// starts with distinct character with
// maximum number of partitions.
#include <bits/stdc++.h>
 
using namespace std;
 
// Returns the number of we can split
// the string
int countWays(string s)
{
    int count[26] = { 0 };
 
    // Finding the frequency of each
    // character.
    for (char x : s)
        count[x - 'a']++;
 
    // making frequency of first character
    // of string equal to 1.
    count[s[0] - 'a'] = 1;
 
    // Finding the product of frequency
    // of occurrence of each character.
    int ans = 1;
    for (int i = 0; i < 26; ++i)
        if (count[i] != 0)
            ans *= count[i];
 
    return ans;
}
 
// Driven Program
int main()
{
    string s = "acbbcc";
    cout << countWays(s) << endl;
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to check if a string can be splitted
// into two strings such that one is divisible by 'a'
// and other is divisible by 'b'.
#include <bits/stdc++.h>
using namespace std;
 
// Finds if it is possible to partition str
// into two parts such that first part is
// divisible by a and second part is divisible
// by b.
void findDivision(string &str, int a, int b)
{
    int len = str.length();
 
    // Create an array of size len+1 and initialize
    // it with 0.
    // Store remainders from left to right when
    // divided by 'a'
    vector<int> lr(len+1, 0);
    lr[0] = (str[0] - '0')%a;
    for (int i=1; i<len; i++)
        lr[i] = ((lr[i-1]*10)%a + (str[i]-'0'))%a;
 
    // Compute remainders from right to left when
    // divided by 'b'
    vector<int> rl(len+1, 0);
    rl[len-1] = (str[len-1] - '0')%b;
    int power10 = 10;
    for (int i= len-2; i>=0; i--)
    {
        rl[i] = (rl[i+1] + (str[i]-'0')*power10)%b;
        power10 = (power10 * 10) % b;
    }
 
    // Find a point that can partition a number
    for (int i=0; i<len-1; i++)
    {
        // If split is not possible at this point
        if (lr[i] != 0)
            continue;
 
        // We can split at i if one of the following
        // two is true.
        // a) All characters after str[i] are 0
        // b) String after str[i] is divisible by b, i.e.,
        //    str[i+1..n-1] is divisible by b.
        if (rl[i+1] == 0)
        {
            cout << "YES\n";
            for (int k=0; k<=i; k++)
                cout << str[k];
 
            cout << ", ";
 
            for (int k=i+1; k<len; k++)
                cout << str[k];
            return;
        }
    }
 
    cout << "NO\n";
}
 
// Driver code
int main()
{
    string str = "123";
    int a = 12, b = 3;
    findDivision(str, a, b);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to check if a string can be splitted
// into two strings such that one is divisible by 'a'
// and other is divisible by 'b'.
#include <bits/stdc++.h>
using namespace std;
 
// Finds if it is possible to partition str
// into two parts such that first part is
// divisible by a and second part is divisible
// by b.
string findDivision(string S, int a, int b)
{
    for (int i = 0; i < S.size() - 1; i++) {
 
        string firstPart = S.substr(0, i + 1);
        string secondPart = S.substr(i + 1);
 
        if (stoi(firstPart) % a == 0
            and stoi(secondPart) % b == 0)
            return firstPart + " " + secondPart;
    }
    return "-1";
}
 
// Driver code
int main()
{
    string str = "125";
    int a = 12, b = 3;
    string result = findDivision(str, a, b);
 
    if (result == "-1") {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
        cout << result << endl;
    }
 
    return 0;
}
 
// This code is contributed by Ishan Khandelwal

Time complexity: linear
Space complexity: constant
#include <bits/stdc++.h>
using namespace std;
// This code kind of uses sliding window technique. First
// checking if string[0] and string[0..n-1] is divisible if
// yes then return else run a loop from 1 to n-1 and check if
// taking this (0-i)index number and (i+1 to n-1)index number
// on our two declared variables if they are divisible by given two numbers respectively
// in any iteration return them simply
string stringPartition(string s, int a, int b)
{
    // code here
    int n = s.length();
  // if length is 1 not possible
    if (n == 1) {
        return "-1";
    }
    else {
      // Checking if number formed bt S[0] and S[1->n-1] is divisible
        int a1 = s[0] - '0';
        int a2 = s[1] - '0';
        int multiplyer = 10;
        for (int i = 2; i < n; i++) {
            a2 = a2 * multiplyer + (s[i] - '0');
        }
        int i = 1;
        if (a1 % a == 0 && a2 % b == 0) {
            string k1 = string(1, s[0]);
            string k2 = "";
            for (int j = 1; j < n; j++)
                k2 += s[j];
            return k1 + " " + k2; // return the numbers formed as string
        }
      // from here by using sliding window technique we will iterate and check for every i
      // that if the two current numbers formed are divisible if yes return
      // else form the two new numbers for next iteration using sliding window technique
        int q1 = 10;
        int q2 = 1;
        for (int i = 1; i < n - 1; i++)
            q2 *= 10;
        while (i < n - 1) {
            char x = s[i];
            int ad = x - '0';
            a1 = a1 * q1 + ad;
            a2 = a2 - q2 * ad;
            if (a1 % a == 0 && a2 % b == 0) {
                string k1 = "";
                string k2 = "";
                for (int j = 0; j < i + 1; j++)
                    k1 += s[j];
                for (int j = i + 1; j < n; j++)
                    k2 += s[j];
                return k1 + " " + k2;
            }
            q2 /= 10;
            i++;
        }
    }
    return "-1";
}
// Driver code
int main()
{
    string str = "123";
    int a = 12, b = 3;
    string result = stringPartition(str, a, b);
 
    if (result == "-1") {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
        cout << result << endl;
    }
 
    return 0;
}
// This code is contributed by Kartikey Singh

Time complexity: linear
Space complexity: constant
#include <bits/stdc++.h>
using namespace std;
 
// c++ function to count ways to divide a
// string in two parts a and b such that
// b/pow(10, p) == a
int calculate(string N)
{
    int len = N.length();
    int l = (len) / 2;
    int count = 0;
 
    for (int i = 1; i <= l; i++) {
 
        // substring representing int a
        string s = N.substr(0, i);
 
        // no of digits in a
        int l1 = s.length();
 
        // consider only most significant
        // l1 characters of remaining string
        // for int b
        string t = N.substr(i, l1);
 
        // if any of a or b contains leading 0s
        // discard this combination
        if (s[0] == '0' || t[0] == '0')
            continue;
 
        // if both are equal
        if (s.compare(t) == 0)
            count++;       
    }
    return count;
}
 
// driver function to test above function
int main()
{
    string N = "2202200";
    cout << calculate(N);
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// C++ program to divide a string
// in n equal parts
#include <iostream>
#include <string.h>
 
using namespace std;
 
class gfg {
 
    // Function to print n equal parts of str
public:
    void divideString(char str[], int n)
    {
 
        int str_size = strlen(str);
        int i;
        int part_size;
 
        // Check if string can be divided in
        // n equal parts
        if (str_size % n != 0) {
            cout << "Invalid Input: String size";
            cout << " is not divisible by n";
            return;
        }
 
        // Calculate the size of parts to
        // find the division points
        part_size = str_size / n;
        for (i = 0; i < str_size; i++) {
            if (i % part_size == 0)
                cout << endl;
            cout << str[i];
        }
    }
};
 
// Driver code
int main()
{
    gfg g;
 
    // length of string is 28
    char str[] = "a_simple_divide_string_quest";
 
    // Print 4 equal parts of the string
    g.divideString(str, 4);
    return 0;
}
 
// This code is contributed by SoM15242

Time complexity: linear
Space complexity: constant
#include <iostream>
 
using namespace std;
 
void divide(string str, int n)
{
 
    if (str.length() % n != 0) {
        cout << "Invalid Input: String size";
        cout << " is not divisible by n";
        return;
    }
 
    int parts = str.length() / n;
    int start = 0;
 
    while (start < str.length()) {
        cout << str.substr(start, parts) << endl;
        start += parts;
        // if(start < str.length()) cout << endl; to ignore
        // final new line
    }
}
 
int main()
{
    string str = "a_simple_divide_string_quest";
    divide(str, 4);
}
 
//Contributed By Jagadeesh

Time complexity: linear
Space complexity: linear
// C++ program to find minimum breaks needed
// to break a string in dictionary words.
#include <bits/stdc++.h>
using namespace std;
 
const int ALPHABET_SIZE = 26;
 
// trie node
struct TrieNode {
    struct TrieNode* children[ALPHABET_SIZE];
 
    // isEndOfWord is true if the node
    // represents end of a word
    bool isEndOfWord;
};
 
// Returns new trie node (initialized to NULLs)
struct TrieNode* getNode(void)
{
    struct TrieNode* pNode = new TrieNode;
 
    pNode->isEndOfWord = false;
 
    for (int i = 0; i < ALPHABET_SIZE; i++)
        pNode->children[i] = NULL;
 
    return pNode;
}
 
// If not present, inserts the key into the trie
// If the key is the prefix of trie node, just
// marks leaf node
void insert(struct TrieNode* root, string key)
{
    struct TrieNode* pCrawl = root;
 
    for (int i = 0; i < key.length(); i++) {
        int index = key[i] - 'a';
        if (!pCrawl->children[index])
            pCrawl->children[index] = getNode();
 
        pCrawl = pCrawl->children[index];
    }
 
    // mark last node as leaf
    pCrawl->isEndOfWord = true;
}
 
// function break the string into minimum cut
// such the every substring after breaking
// in the dictionary.
void minWordBreak(struct TrieNode* root,
          string key, int start, int* min_Break,
                                 int level = 0)
{
    struct TrieNode* pCrawl = root;
 
    // base case, update minimum Break
    if (start == key.length()) {       
        *min_Break = min(*min_Break, level - 1);
        return;
    }
 
    // traverse given key(pattern)
    int minBreak = 0;  
    for (int i = start; i < key.length(); i++) {
        int index = key[i] - 'a';
        if (!pCrawl->children[index])
            return;
 
        // if we find a condition where we can
        // move to the next word in a trie
        // dictionary
        if (pCrawl->children[index]->isEndOfWord)
            minWordBreak(root, key, i + 1,
                           min_Break, level + 1);
 
        pCrawl = pCrawl->children[index];
    }
}
 
// Driver program to test above functions
int main()
{
    string dictionary[] = { "Cat", "Mat",
   "Ca", "Ma", "at", "C", "Dog", "og", "Do" };
    int n = sizeof(dictionary) / sizeof(dictionary[0]);
    struct TrieNode* root = getNode();
 
    // Construct trie
    for (int i = 0; i < n; i++)
        insert(root, dictionary[i]);
    int min_Break = INT_MAX;
 
    minWordBreak(root, "CatMatat", 0, &min_Break, 0);
    cout << min_Break << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// A recursive program to print all possible
// partitions of a given string into dictionary
// words
#include <iostream>
using namespace std;
 
/* A utility function to check whether a word
  is present in dictionary or not.  An array of
  strings is used for dictionary.  Using array
  of strings for dictionary is definitely not
  a good idea. We have used for simplicity of
  the program*/
int dictionaryContains(string &word)
{
    string dictionary[] = {"mobile","samsung","sam","sung",
                            "man","mango", "icecream","and",
                            "go","i","love","ice","cream"};
    int n = sizeof(dictionary)/sizeof(dictionary[0]);
    for (int i = 0; i < n; i++)
        if (dictionary[i].compare(word) == 0)
            return true;
    return false;
}
 
// Prototype of wordBreakUtil
void wordBreakUtil(string str, int size, string result);
 
// Prints all possible word breaks of given string
void wordBreak(string str)
{
    // Last argument is prefix
    wordBreakUtil(str, str.size(), "");
}
 
// Result store the current prefix with spaces
// between words
void wordBreakUtil(string str, int n, string result)
{
    //Process all prefixes one by one
    for (int i=1; i<=n; i++)
    {
        // Extract substring from 0 to i in prefix
        string prefix = str.substr(0, i);
 
        // If dictionary contains this prefix, then
        // we check for remaining string. Otherwise
        // we ignore this prefix (there is no else for
        // this if) and try next
        if (dictionaryContains(prefix))
        {
            // If no more elements are there, print it
            if (i == n)
            {
                // Add this element to previous prefix
                result += prefix;
                cout << result << endl;
                return;
            }
            wordBreakUtil(str.substr(i, n-i), n-i,
                                result + prefix + " ");
        }
    }     
}
 
//Driver Code
int main()
{
   
    // Function call
    cout << "First Test:\n";
    wordBreak("iloveicecreamandmango");
 
    cout << "\nSecond Test:\n";
    wordBreak("ilovesamsungmobile");
    return 0;
}

Time complexity: np
Space complexity: quadratic
// C++ program to find length of
// the longest balanced subsequence
#include <bits/stdc++.h>
using namespace std;
 
int maxLength(char s[], int n)
{
    int dp[n][n];
    memset(dp, 0, sizeof(dp));
 
    // Considering all balanced
    // substrings of length 2
    for (int i = 0; i < n - 1; i++)
        if (s[i] == '(' && s[i + 1] == ')')
            dp[i][i + 1] = 2;
 
    // Considering all other substrings
    for (int l = 2; l < n; l++) {
        for (int i = 0, j = l; j < n; i++, j++) {
            if (s[i] == '(' && s[j] == ')')
                dp[i][j] = 2 + dp[i + 1][j - 1];
 
            for (int k = i; k < j; k++)
                dp[i][j] = max(dp[i][j],
                               dp[i][k] + dp[k + 1][j]);
        }
    }
 
    return dp[0][n - 1];
}
 
// Driver Code
int main()
{
    char s[] = "()(((((()";
    int n = strlen(s);
    cout << maxLength(s, n) << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// C++ program to find length of
// the longest balanced subsequence
#include <bits/stdc++.h>
using namespace std;
 
int maxLength(char s[], int n)
{
    // As it's subsequence - assuming first
    // open brace would map to a first close
    // brace which occurs after the open brace
    // to make subsequence balanced and second
    // open brace would map to second close
    // brace and so on.
 
    // Variable to count all the open brace
    // that does not have the corresponding
    // closing brace.
    int invalidOpenBraces = 0;
 
    // To count all the close brace that
    // does not have the corresponding open brace.
    int invalidCloseBraces = 0;
 
    // Iterating over the String
    for (int i = 0; i < n; i++) {
        if (s[i] == '(') {
 
            // Number of open braces that
            // hasn't been closed yet.
            invalidOpenBraces++;
        }
        else {
            if (invalidOpenBraces == 0) {
 
                // Number of close braces that
                // cannot be mapped to any open
                // brace.
                invalidCloseBraces++;
            }
            else {
 
                // Mapping the ith close brace
                // to one of the open brace.
                invalidOpenBraces--;
            }
        }
    }
    return (
        n - (invalidOpenBraces
             + invalidCloseBraces));
}
 
// Driver Code
int main()
{
    char s[] = "()(((((()";
    int n = strlen(s);
    cout << maxLength(s, n) << endl;
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to evaluate value of an expression.
#include <bits/stdc++.h>
 
using namespace std;
 
int evaluateBoolExpr(string s)
{
    int n = s.length();
 
    // Traverse all operands by jumping
    // a character after every iteration.
    for (int i = 0; i < n; i += 2) {
 
        // If operator next to current operand
        // is AND.
        if (s[i + 1] == 'A') {
            if (s[i + 2] == '0'|| s[i] == '0')
                s[i + 2] = '0';
            else
                s[i + 2] = '1';
        }
 
        // If operator next to current operand
        // is OR.
        else if (s[i + 1] == 'B') {
            if (s[i + 2] == '1'|| s[i] == '1')
                s[i + 2] = '1';
            else
                s[i + 2] = '0';
        }
 
        // If operator next to current operand
        // is XOR (Assuming a valid input)
        else {
            if (s[i + 2] == s[i])
                s[i + 2] = '0';
            else
                s[i + 2] = '1';
        }
    }
    return s[n - 1] -'0';
}
 
// Driver code
int main()
{
    string s = "1C1B1B0A0";
    cout << evaluateBoolExpr(s);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ Program to find all combinations of Non-
// overlapping substrings formed from given
// string
#include <iostream>
using namespace std;
 
// find all combinations of non-overlapping
// substrings formed by input string str
// index – index of the next character to
//          be processed
// out - output string so far
void findCombinations(string str, int index, string out)
{
    if (index == str.length())
        cout << out << endl;
 
    for (int i = index; i < str.length(); i++)
    {
        // append substring formed by str[index,
        // i] to output string
        findCombinations(
            str,
            i + 1,
            out + "(" + str.substr(index, i + 1 - index)
                + ")");
    }
}
 
// Driver Code
int main()
{
    // input string
    string str = "abcd";
 
    findCombinations(str, 0, "");
 
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// C++ program to find an index k which
// decides the number of opening brackets
// is equal to the number of closing brackets
#include<bits/stdc++.h>
using namespace std;
 
// Function to find an equal index
int findIndex(string str)
{
    int len = str.length();
    int open[len+1], close[len+1];
    int index = -1;
    memset(open, 0, sizeof (open));
    memset(close, 0, sizeof (close));
 
    open[0] = 0;
    close[len] = 0;
    if (str[0]=='(')
        open[1] = 1;
    if (str[len-1] == ')')
        close[len-1] = 1;
 
    // Store the number of opening brackets
    // at each index
    for (int i = 1; i < len; i++)
    {
        if ( str[i] == '(' )
            open[i+1] = open[i] + 1;
        else
            open[i+1] = open[i];
    }
 
    // Store the number of closing brackets
    // at each index
    for (int i = len-2; i >= 0; i--)
    {
        if ( str[i] == ')' )
            close[i] = close[i+1] + 1;
        else
            close[i] = close[i+1];
    }
 
    // check if there is no opening or closing
    // brackets
    if (open[len] == 0)
        return len;
    if (close[0] == 0)
        return 0;
 
    // check if there is any index at which
    // both brackets are equal
    for (int i=0; i<=len; i++)
        if (open[i] == close[i])
            index = i;
 
    return index;
}
 
// Driver code
int main()
{
    string str = "(()))(()()())))";
    cout << findIndex(str);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to find an index k which
// decides the number of opening brackets
// is equal to the number of closing brackets
#include <bits/stdc++.h>
using namespace std;
 
// Function to find an equal index
int findIndex(string str)
{
    // STL to count occurrences of ')'
    int cnt_close = count(str.begin(), str.end(), ')');
    for (int i = 0; str[i] != '\0'; i++)
        if (cnt_close == i)
            return i;
    // If no opening brackets
    return str.size();
}
 
// Driver code
int main()
{
    string str = "(()))(()()())))";
    cout << findIndex(str);
    return 0;
}
 
// This code is contributed by Dhananjay Dhawale @chessnoobdj

Time complexity: linear
Space complexity: constant
// C++ program to find sum of given array of
// string type in integer form
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the sum of given array
int calculateSum(string arr[], int n)
{  
    // if string is empty
    if (n == 0)
       return 0;
 
    string s = arr[0];
 
    // stoi function to convert
    // string into integer
    int value = stoi(s);
    int sum = value;
 
    for (int i = 2; i < n; i = i + 2)
    {
        s = arr[i];
 
        // stoi function to convert
        // string into integer
        int value = stoi(s);
 
        // Find operator
        char operation = arr[i - 1][0];
 
        // If operator is equal to '+',
        // add value in sum variable
        // else subtract
        if (operation == '+')
            sum += value;
        else
            sum -= value;
    }
    return sum;
}
 
// Driver Function
int main()
{
    string arr[] = { "3", "+", "4", "-",
                     "7", "+", "13" };
    int n = sizeof(arr) / sizeof(arr[0]);  
    cout << calculateSum(arr, n);  
    return 0;
}

Time complexity: linear
Space complexity: constant