Banana-Leopard/TASTY huggingface dataset:
// C++ implementation to print the bracket number
#include <bits/stdc++.h>
 
using namespace std;
 
// function to print the bracket number
void printBracketNumber(string exp, int n)
{
    // used to print the bracket number
    // for the left bracket
    int left_bnum = 1;
     
    // used to obtain the bracket number
    // for the right bracket
    stack<int> right_bnum;
     
    // traverse the given expression 'exp'
    for (int i = 0; i < n; i++) {
         
        // if current character is a left bracket
        if (exp[i] == '(') {
            // print 'left_bnum',
            cout << left_bnum << " ";
             
            // push 'left_bnum' on to the stack 'right_bnum'
            right_bnum.push(left_bnum);
             
            // increment 'left_bnum' by 1
            left_bnum++;
        }
         
        // else if current character is a right bracket
        else if(exp[i] == ')') {
 
            // print the top element of stack 'right_bnum'
            // it will be the right bracket number
            cout << right_bnum.top() << " ";
             
            // pop the top element from the stack
            right_bnum.pop();
        }
    }
}
 
// Driver program to test above
int main()
{
    string exp = "(a+(b*c))+(d/e)";
    int n = exp.size();
     
    printBracketNumber(exp, n);
     
    return 0;
}

Time complexity: linear
Space complexity: linear
/* C++ program to construct string from binary tree*/
#include <bits/stdc++.h>
using namespace std;
 
/* A binary tree node has data, pointer to left
   child and a pointer to right child */
struct Node {
    int data;
    Node *left, *right;
};
 
/* Helper function that allocates a new node */
Node* newNode(int data)
{
    Node* node = (Node*)malloc(sizeof(Node));
    node->data = data;
    node->left = node->right = NULL;
    return (node);
}
 
// Function to construct string from binary tree
void treeToString(Node* root, string& str)
{
    // bases case
    if (root == NULL)
        return;
 
    // push the root data as character
    str.push_back(root->data + '0');
 
    // if leaf node, then return
    if (!root->left && !root->right)
        return;
 
    // for left subtree
    str.push_back('(');
    treeToString(root->left, str);
    str.push_back(')');
 
    // only if right child is present to
    // avoid extra parenthesis
    if (root->right) {
        str.push_back('(');
        treeToString(root->right, str);
        str.push_back(')');
    }
}
 
// Driver Code
int main()
{
    /* Let us construct below tree
                1
               / \
              2   3
             / \   \
            4   5   6    */
    struct Node* root = newNode(1);
    root->left = newNode(2);
    root->right = newNode(3);
    root->left->left = newNode(4);
    root->left->right = newNode(5);
    root->right->right = newNode(6);
    string str = "";
    treeToString(root, str);
    cout << str;
}

Time complexity: linear
Space complexity: linear
// Simple C++ program to convert all substrings from
// decimal to given base.
#include <bits/stdc++.h>
using namespace std;
 
int substringConversions(string str, int k, int b)
{
    for (int i=0; i + k <= str.size(); i++)
    {
        // Saving substring in sub
        string sub = str.substr(i, k);       
         
        // Evaluating decimal for current substring
        // and printing it.
        int sum = 0, counter = 0;
        for (int i = sub.size() - 1; i >= 0; i--)
        {
            sum = sum + ((sub.at(i) - '0') * pow(b, counter));
            counter++;
        }       
        cout << sum << " ";
    }
}
 
// Driver code
int main()
{
    string str = "12212";
    int b = 3, k = 3;
    substringConversions(str, b, k);   
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// Efficient C++ program to convert all substrings from
// decimal to given base.
#include <bits/stdc++.h>
using namespace std;
 
int substringConversions(string str, int k, int b)
{
   int i = 0, sum = 0, counter = k-1;
 
    // Computing the decimal of first window
    for (i; i < k; i++)
    {
        sum = sum + ((str.at(i) - '0') * pow(b, counter));
        counter--;
    }
    cout << sum << " ";
     
    // prev stores the previous decimal
    int prev = sum;
            
    // Computing decimal equivalents of all other windows
    sum = 0, counter = 0;
    for (i; i < str.size(); i++)
    {
        // Subtracting weight of the element pushed out of window
        sum = prev - ((str.at(i - k) - '0') * pow(b, k-1));
         
        // Multiplying the decimal by base to formulate other window
        sum = sum * b;
         
        // Adding the new element of window to sum
        sum = sum + (str.at(i) - '0');
         
        // Decimal of current window
        cout << sum << " ";
         
        // Updating prev
        prev = sum;
         
        counter++;
    }
}
 
// Driver code
int main()
{
    string str = "12212";
    int b = 3, k = 3;
    substringConversions(str, b, k);   
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to demonstrate above steps of
// binary fractional to decimal conversion
#include<bits/stdc++.h>
using namespace std;
 
// Function to convert binary fractional to
// decimal
double binaryToDecimal(string binary, int len)
{
    // Fetch the radix point
    size_t point = binary.find('.');
 
    // Update point if not found
    if (point == string::npos)
        point = len;
 
    double intDecimal = 0, fracDecimal = 0, twos = 1;
 
    // Convert integral part of binary to decimal
    // equivalent
    for (int i = point-1; i>=0; --i)
    {
        // Subtract '0' to convert character
        // into integer
        intDecimal += (binary[i] - '0') * twos;
        twos *= 2;
    }
 
    // Convert fractional part of binary to
    // decimal equivalent
    twos = 2;
    for (int i = point+1; i < len; ++i)
    {
        fracDecimal += (binary[i] - '0') / twos;
        twos *= 2.0;
    }
 
    // Add both integral and fractional part
    return intDecimal + fracDecimal;
}
 
// Driver code
int main()
{
    string n = "110.101";
    cout << binaryToDecimal(n, n.length()) << "\n";
 
    n = "101.1101";
    cout << binaryToDecimal(n, n.length());
 
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to convert fractional decimal
// to binary number
#include<bits/stdc++.h>
using namespace std;
 
// Function to convert decimal to binary upto
// k-precision after decimal point
string decimalToBinary(double num, int k_prec)
{
    string binary = "";
 
    // Fetch the integral part of decimal number
    int Integral = num;
 
    // Fetch the fractional part decimal number
    double fractional = num - Integral;
 
    // Conversion of integral part to
    // binary equivalent
    while (Integral)
    {
        int rem = Integral % 2;
 
        // Append 0 in binary
        binary.push_back(rem +'0');
 
        Integral /= 2;
    }
 
    // Reverse string to get original binary
    // equivalent
    reverse(binary.begin(),binary.end());
 
    // Append point before conversion of
    // fractional part
    binary.push_back('.');
 
    // Conversion of fractional part to
    // binary equivalent
    while (k_prec--)
    {
        // Find next bit in fraction
        fractional *= 2;
        int fract_bit = fractional;
 
        if (fract_bit == 1)
        {
            fractional -= fract_bit;
            binary.push_back(1 + '0');
        }
        else
            binary.push_back(0 + '0');
    }
 
    return binary;
}
 
// Driver code
int main()
{
 
    double n = 4.47;
    int k = 3;
    cout << decimalToBinary(n, k) << "\n";
 
    n = 6.986 , k = 5;
    cout << decimalToBinary(n, k);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ implementation to convert a
// sentence into its equivalent
// mobile numeric keypad sequence
#include <bits/stdc++.h>
using namespace std;
 
// Function which computes the sequence
string printSequence(string arr[], string input)
{
    string output = "";
 
    // length of input string
    int n = input.length();
    for (int i = 0; i < n; i++) {
        // Checking for space
        if (input[i] == ' ')
            output = output + "0";
 
        else {
            // Calculating index for each
            // character
            int position = input[i] - 'A';
            output = output + arr[position];
        }
    }
 
    // Output sequence
    return output;
}
 
// Driver Code
int main()
{
    // storing the sequence in array
    string str[]
        = { "2",   "22",  "222", "3",   "33",   "333", "4",
            "44",  "444", "5",   "55",  "555",  "6",   "66",
            "666", "7",   "77",  "777", "7777", "8",   "88",
            "888", "9",   "99",  "999", "9999" };
 
    string input = "GEEKSFORGEEKS";
    cout << printSequence(str, input);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ Program for above implementation
#include <bits/stdc++.h>
using namespace std;
 
// Function to check is it possible to convert
// first string into another string or not.
bool isItPossible(string str1, string str2, int m, int n)
{
 
    // To Check Length of Both String is Equal or Not
    if (m != n)
        return false;
 
    // To Check  Frequency of A's and  B's are
    // equal in both strings or not.
    if (count(str1.begin(), str1.end(), 'A') !=
           count(str2.begin(), str2.end(), 'A') ||
        count(str1.begin(), str1.end(), 'B') !=
            count(str2.begin(), str2.end(), 'B'))
        return false;
 
    // Start traversing
    for (int i = 0; i < m; i++) {
        if (str1[i] != '#') {
            for (int j = 0; j < n; j++) {
 
                // To Check no two elements cross each other.
                if ((str2[j] != str1[i]) && str2[j] != '#')
                    return false;
 
                if (str2[j] == str1[i]) {
                    str2[j] = '#';
 
                    // To Check Is it Possible to Move
                    // towards Left or not.
                    if (str1[i] == 'A' && i < j)
                        return false;
 
                    // To Check Is it Possible to Move
                    // towards Right or not.
                    if (str1[i] == 'B' && i > j)
                        return false;
 
                    break;
                }
            }
        }
    }
 
    return true;
}
 
// Drivers code
int main()
{
    string str1 = "A#B#";
    string str2 = "A##B";
 
    int m = str1.length();
    int n = str2.length();
 
    isItPossible(str1, str2, m, n) ? cout << "Yes\n"
                                   : cout << "No\n";
 
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// CPP Program to convert str1 to str2 in
// exactly k operations
#include <bits/stdc++.h>
using namespace std;
 
// Returns true if it is possible to convert
// str1 to str2 using k operations.
bool isConvertible(string str1, string str2,
                                      int k)
{
    // Case A (i)
    if ((str1.length() + str2.length()) < k)
        return true;
 
    // finding common length of both string
    int commonLength = 0;
    for (int i = 0; i < min(str1.length(),
                           str2.length()); i++) {
        if (str1[i] == str2[i])
            commonLength++;
        else
            break;
    }
 
    // Case A (ii)-
    if ((k - str1.length() - str2.length() +
                     2 * commonLength) % 2 == 0)
        return true;
 
    // Case B-
    return false;
}
 
// driver program
int main()
{
    string str1 = "geek", str2 = "geek";
    int k = 7;
    if (isConvertible(str1, str2, k))
       cout << "Yes";
    else
       cout << "No";
 
    str1 = "geeks",  str2 = "geek";
    k = 5;   
    cout << endl;
    if (isConvertible(str1, str2, k))
       cout << "Yes";
    else
       cout << "No";
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ Program to convert decimal number to
// roman numerals
#include <bits/stdc++.h>
using namespace std;
 
// Function to convert decimal to Roman Numerals
int printRoman(int number)
{
    int num[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
    string sym[] = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
    int i=12;   
    while(number>0)
    {
      int div = number/num[i];
      number = number%num[i];
      while(div--)
      {
        cout<<sym[i];
      }
      i--;
    }
}
 
//Driver program
int main()
{
    int number = 3549;
 
    printRoman(number);
 
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ Program for above approach
#include <bits/stdc++.h>
using namespace std;
 
// Function to calculate roman equivalent
string intToRoman(int num)
{
    // storing roman values of digits from 0-9
    // when placed at different places
    string m[] = { "", "M", "MM", "MMM" };
    string c[] = { "",  "C",  "CC",  "CCC",  "CD",
                   "D", "DC", "DCC", "DCCC", "CM" };
    string x[] = { "",  "X",  "XX",  "XXX",  "XL",
                   "L", "LX", "LXX", "LXXX", "XC" };
    string i[] = { "",  "I",  "II",  "III",  "IV",
                   "V", "VI", "VII", "VIII", "IX" };
 
    // Converting to roman
    string thousands = m[num / 1000];
    string hundreds = c[(num % 1000) / 100];
    string tens = x[(num % 100) / 10];
    string ones = i[num % 10];
 
    string ans = thousands + hundreds + tens + ones;
 
    return ans;
}
 
// Driver program to test above function
int main()
{
    int number = 3549;
    cout << intToRoman(number);
    return 0;
}

Time complexity: linear
Space complexity: constant
// cpp program to check if a string can
// be converted to another string by
// performing operations
#include <bits/stdc++.h>
using namespace std;
 
// function to check if a string can be
// converted to  another string by
// performing following operations
bool check(string s1, string s2)
{
    // calculates length
    int n = s1.length();
    int m = s2.length();
 
    bool dp[n + 1][m + 1];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            dp[i][j] = false;
        }
    }
    // mark 1st position as true
    dp[0][0] = true;
 
    // traverse for all DPi, j
    for (int i = 0; i < s1.length(); i++) {
        for (int j = 0; j <= s2.length(); j++) {
 
            // if possible for to convert i
            // characters of s1 to j characters
            // of s2
            if (dp[i][j]) {
 
                // if upper_case(s1[i])==s2[j]
                // is same
                if (j < s2.length() &&
                    (toupper(s1[i]) == s2[j]))
                    dp[i + 1][j + 1] = true;
 
                // if not upper then deletion is
                // possible
                if (!isupper(s1[i]))
                    dp[i + 1][j] = true;
            }
        }
    }
 
    return (dp[n][m]);
}
 
// driver code
int main()
{
    string s1 = "daBcd";
    string s2 = "ABC";
 
    if (check(s1, s2))
        cout << "YES";
    else
        cout << "NO";
 
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// CPP code to transform string
#include <bits/stdc++.h>
using namespace std;
 
// Function to change
// character's case
string change_case(string a)
{
    int l = a.length();
     
    for(int i = 0 ; i < l ; i++)
    {
        // If character is lowercase
        // change to uppercase
        if(a[i] >= 'a' && a[i] <= 'z')
            a[i] = a[i] - 32;
             
        // If character is uppercase
        // change to lowercase
        else if(a[i] >= 'A' && a[i] <= 'Z')
            a[i] = a[i] + 32;
    }
     
    return a;
     
}
 
// Function to delete vowels
string delete_vowels(string a)
{
    string temp = "";
    int l = a.length();
    for(int i = 0 ; i < l ; i++)
    {
        //If character is consonant
        if(a[i] != 'a' && a[i] != 'e' &&
           a[i] != 'i' && a[i] != 'o' &&
           a[i] != 'u' && a[i] != 'A' &&
           a[i] != 'E' && a[i] != 'O' &&
           a[i] != 'U'&& a[i] != 'I')
            temp += a[i];
    }
     
    return temp;
     
}
 
// Function to insert "#"
string insert_hash(string a)
{
    string temp = "";
    int l = a.length();
     
    for(int i = 0 ; i < l ; i++)
    {
        // If character is not special
        if((a[i] >= 'a' && a[i] <= 'z') ||
           (a[i] >= 'A' && a[i] <= 'Z'))
            temp = temp + '#' + a[i];
        else
            temp = temp + a[i];
    }
     
    return temp;
     
}
 
// Function to transform string
void transformSting(string a)
{
    string b = delete_vowels(a);
    string c = change_case(b);
    string d = insert_hash(c);
     
    //corner case
    // when all the words of string are vowel then string empty after deletion
    if(d=="")
      cout<<"-1"<<endl;
    else
    cout << d<<endl;
}
 
// Driver function
int main()
{
    string a = "SunshinE!!";
    string b = "aeiou";
    // Calling function
    transformSting(a);
    transformSting(b);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ implementation of above approach
#include <bits/stdc++.h>
using namespace std;
 
// A utility function to swap characters
void swap ( char* a, char* b )
{
    char t = *a;
    *a = *b;
    *b = t;
}
 
// A utility function to reverse string str[low..high]
void reverse ( char* str, int low, int high )
{
    while ( low < high )
    {
        swap( &str[low], &str[high] );
        ++low;
        --high;
    }
}
 
// Cycle leader algorithm to move all even
//  positioned elements at the end.
void cycleLeader ( char* str, int shift, int len )
{
    int j;
    char item;
 
    for (int i = 1; i < len; i *= 3 )
    {
        j = i;
 
        item = str[j + shift];
        do
        {
            // odd index
            if ( j & 1 )
                j = len / 2 + j / 2;
            // even index
            else
                j /= 2;
 
            // keep the back-up of element at new position
            swap (&str[j + shift], &item);
        }
        while ( j != i );
    }
}
 
// The main function to transform a string. This function 
// mainly uses cycleLeader() to transform
void moveNumberToSecondHalf( char* str )
{
    int k, lenFirst;
 
    int lenRemaining = strlen( str );
    int shift = 0;
 
    while ( lenRemaining )
    {
        k = 0;
 
        // Step 1: Find the largest prefix
        // subarray of the form 3^k + 1
        while ( pow( 3, k ) + 1 <= lenRemaining )
            k++;
        lenFirst = pow( 3, k - 1 ) + 1;
        lenRemaining -= lenFirst;
 
        // Step 2: Apply cycle leader algorithm
        // for the largest subarrau
        cycleLeader ( str, shift, lenFirst );
 
        // Step 4.1: Reverse the second half of first subarray
        reverse ( str, shift / 2, shift - 1 );
 
        // Step 4.2: Reverse the first half of second sub-string.
        reverse ( str, shift, shift + lenFirst / 2 - 1 );
 
        // Step 4.3 Reverse the second half of first sub-string
        // and first half of second sub-string together
        reverse ( str, shift / 2, shift + lenFirst / 2 - 1 );
 
        // Increase the length of first subarray
        shift += lenFirst;
    }
}
 
// Driver program to test above function
int main()
{
    char str[] = "a1b2c3d4e5f6g7";
    moveNumberToSecondHalf( str );
    cout<<str;
    return 0;
}
 
// This is code is contributed by rathbhupendra

Time complexity: quadratic
Space complexity: constant
// C++ program to count the distinct transformation
// of one string to other.
#include <bits/stdc++.h>
using namespace std;
 
int countTransformation(string a, string b)
{
    int n = a.size(), m = b.size();
 
    // If b = "" i.e., an empty string. There
    // is only one way to transform (remove all
    // characters)
    if (m == 0)
        return 1;
 
    int dp[m][n];
    memset(dp, 0, sizeof(dp));
 
    // Fill dp[][] in bottom up manner
    // Traverse all character of b[]
    for (int i = 0; i < m; i++) {
 
        // Traverse all characters of a[] for b[i]
        for (int j = i; j < n; j++) {
 
            // Filling the first row of the dp
            // matrix.
            if (i == 0) {
                if (j == 0)
                    dp[i][j] = (a[j] == b[i]) ? 1 : 0;
                else if (a[j] == b[i])
                    dp[i][j] = dp[i][j - 1] + 1;
                else
                    dp[i][j] = dp[i][j - 1];
            }
 
            // Filling other rows.
            else {
                if (a[j] == b[i])
                    dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1];
                else
                    dp[i][j] = dp[i][j - 1];
            }
        }
    }
 
    return dp[m - 1][n - 1];
}
 
// Driver code
int main()
{
    string a = "abcccdf", b = "abccdf";
    cout << countTransformation(a, b) << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// CPP Program to convert prefix to postfix
#include <iostream>
#include <stack>
using namespace std;
 
// function to check if character is operator or not
bool isOperator(char x)
{
    switch (x) {
    case '+':
    case '-':
    case '/':
    case '*':
        return true;
    }
    return false;
}
 
// Convert prefix to Postfix expression
string preToPost(string pre_exp)
{
 
    stack<string> s;
    // length of expression
    int length = pre_exp.size();
 
    // reading from right to left
    for (int i = length - 1; i >= 0; i--)
    {
        // check if symbol is operator
        if (isOperator(pre_exp[i]))
        {
            // pop two operands from stack
            string op1 = s.top();
            s.pop();
            string op2 = s.top();
            s.pop();
 
            // concat the operands and operator
            string temp = op1 + op2 + pre_exp[i];
 
            // Push string temp back to stack
            s.push(temp);
        }
 
        // if symbol is an operand
        else {
 
            // push the operand to the stack
            s.push(string(1, pre_exp[i]));
        }
    }
 
    // stack contains only the Postfix expression
    return s.top();
}
 
// Driver Code
int main()
{
    string pre_exp = "*-A/BC-/AKL";
    cout << "Postfix : " << preToPost(pre_exp);
    return 0;
}

Time complexity: linear
Space complexity: linear
// CPP program to find infix for
// a given postfix.
#include <bits/stdc++.h>
using namespace std;
 
bool isOperand(char x)
{
   return (x >= 'a' && x <= 'z') ||
          (x >= 'A' && x <= 'Z');
}
 
// Get Infix for a given postfix
// expression
string getInfix(string exp)
{
    stack<string> s;
 
    for (int i=0; exp[i]!='\0'; i++)
    {
        // Push operands
        if (isOperand(exp[i]))
        {
           string op(1, exp[i]);
           s.push(op);
        }
 
        // We assume that input is
        // a valid postfix and expect
        // an operator.
        else
        {
            string op1 = s.top();
            s.pop();
            string op2 = s.top();
            s.pop();
            s.push("(" + op2 + exp[i] +
                   op1 + ")");
        }
    }
 
    // There must be a single element
    // in stack now which is the required
    // infix.
    return s.top();
}
 
// Driver code
int main()
{
    string exp = "ab*c+";
    cout << getInfix(exp);
    return 0;
}

Time complexity: linear
Space complexity: linear