Banana-Leopard/TASTY huggingface dataset:
// A Simple Iterative C++ program to reverse
// a string
#include <bits/stdc++.h>
using namespace std;
 
// Function to reverse a string
void reverseStr(string& str)
{
    int n = str.length();
 
    // Swap character starting from two
    // corners
    for (int i=0, j=n-1; i<j; i++,j--)
        swap(str[i], str[j]); 
}
 
// Driver program
int main()
{
    string str = "geeksforgeeks";
    reverseStr(str);
    cout << str;
    return 0;
}

Time complexity: linear
Space complexity: constant
// Recursive C++ program to reverse a string
#include <bits/stdc++.h>
using namespace std;
 
void recursiveReverse(string &str, int i = 0)
{
    int n = str.length();
    if (i == n / 2)
        return;
    swap(str[i], str[n - i - 1]);
    recursiveReverse(str, i + 1);
}
 
// Driver program
int main()
{
    string str = "geeksforgeeks";
    recursiveReverse(str);
    cout << str;
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to reverse string using
// reverse() method
 
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    // Given String
    string str = "geeksforgeeks";
 
    // reverse function in C++ STL
    reverse(str.begin(), str.end());
 
    // Printing the reversed string
    cout << str;
 
    return 0;
}
 
// contributed by akashish__

Time complexity: linear
Space complexity: constant
//C++ program to reverse string without
//affecting it's special character
 
#include<bits/stdc++.h>
using namespace std;
void reverse(string s){
    //creating character array of size
    // equal to length of string
    char temp[s.length()];
    int x=0;
    for (int i = 0; i < s.length(); i++)
    {
        if(s[i]>='a' && s[i]<='z' || s[i]>='A' && s[i]<='Z'){
            //storing elements in array
          temp[x]=s[i];
          x++;
        }
    }
    //reversing the character array
    reverse(temp,temp+x);
 
     
    x=0;
    for (int i = 0; i < s.length(); i++)
    {
        if(s[i]>='a' && s[i]<='z' || s[i]>='A' && s[i]<='Z'){
            //updating the original string
            s[i]=temp[x];
            x++;
        }
    }
    cout<<"reversed string is: "<<s;
     
}
//driver code
int main() {
string s="Ab,c,de!$";
//function call
reverse(s);
return 0;
}
 
//this code is contributed by Machhaliya Muhammad

Time complexity: linear
Space complexity: linear
// C++ program to reverse a string  with special characters
#include <bits/stdc++.h>
using namespace std;
 
// Returns true if x is an alphabetic character, false
// otherwise
bool isAlphabet(char x)
{
    return ((x >= 'A' && x <= 'Z') || (x >= 'a' && x <= 'z'));
}
 
void reverse(char str[])
{
    // Initialize left and right pointers
    int r = strlen(str) - 1, l = 0;
 
    // Traverse string from both ends until 'l' and 'r'
    while (l < r) {
        // Ignore special characters
        if (!isAlphabet(str[l]))
            l++;
        else if (!isAlphabet(str[r]))
            r--;
 
        else // Both str[l] and str[r] are not special
        {
            swap(str[l], str[r]);
            l++;
            r--;
        }
    }
}
 
// Driver code
int main()
{
    char str[] = "a!!!b.c.d,e'f,ghi";
    cout << "Input string: " << str << endl;
    reverse(str);
    cout << "Output string: " << str << endl;
    return 0;
}
 
// This code is contributed by Sania Kumari Gupta

Time complexity: linear
Space complexity: constant
// C++ program to reverse a string preserving
// spaces.
#include <iostream>
using namespace std;
 
// Function to reverse the string
// and preserve the space position
string reverses(string str)
{
    // Mark spaces in result
    int n = str.size();
    string result(n, '\0');
    for (int i = 0; i < n; i++)
        if (str[i] == ' ')
            result[i] = ' ';
 
    // Traverse input string from beginning
    // and put characters in result from end
    int j = n - 1;
    for (int i = 0; i < str.length(); i++) {
        // Ignore spaces in input string
        if (str[i] != ' ') {
            // ignore spaces in result.
            while(result[j] == ' ')
                j--;
 
            result[j] = str[i];
            j--;
        }
    }
 
    return result;
}
 
// Driver code
int main()
{
    string str = "internship at geeks for geeks";
    cout << reverses(str) << endl;
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to implement
// the above approach
#include <iostream>
using namespace std;
 
void preserveSpace(string &str)
{
    int n = str.length();
 
    // Initialize two pointers as two corners
    int start = 0;
    int end = n - 1;
 
    // Move both pointers toward each other
    while (start < end) {
 
        // If character at start or end is space,
        // ignore it
        if (str[start] == ' ') {
            start++;
            continue;
        }
        else if (str[end] == ' ') {
            end--;
            continue;
        }
 
        // If both are not spaces, do swap
        else {
            swap(str[start], str[end]);
            start++;
            end--;
        }
    }
}
 
// Driver code
int main()
{
    string str = "internship at geeks for geeks";
    preserveSpace(str);
    cout << str;
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ Program to reverse a string without
// using temp variable
#include <bits/stdc++.h>
using namespace std;
  
// Function to reverse string and return reversed string
string reversingString(string str, int start, int end)
{
    // Iterate loop upto start not equal to end
    while (start < end)
    {
        // XOR for swapping the variable
        str[start] ^= str[end];
        str[end] ^= str[start];
        str[start] ^= str[end];
  
        ++start;
        --end;
    }
    return str;
}
  
// Driver Code
int main()
{
    string s = "GeeksforGeeks";
    cout << reversingString(s, 0, 12);
    return 0;
}

Time complexity: linear
Space complexity: constant
// Reversing a string using reverse()
#include<bits/stdc++.h>
using namespace std;
  
int main()
{
   string str = "geeksforgeeks";
      
   // Reverse str[begin..end]
   reverse(str.begin(), str.end());
      
   cout << str;
   return 0;
}

Time complexity: linear
Space complexity: constant
// CPP Program for removing characters
// from reversed string where vowels are
// present in original string
#include <bits/stdc++.h>
using namespace std;
 
// Function for replacing the string
void replaceOriginal(string s, int n)
{
    // initialize a string of length n
    string r(n, ' ');
 
    // Traverse through all characters of string
    for (int i = 0; i < n; i++) {
 
        // assign the value to string r
        // from last index of string s
        r[i] = s[n - 1 - i];
 
        // if s[i] is a consonant then
        // print r[i]
        if (s[i] != 'a' && s[i] != 'e' && s[i] != 'i'
            && s[i] != 'o' && s[i] != 'u') {
            cout << r[i];
        }
    }
    cout << endl;
}
 
// Driver function
int main()
{
    string s = "geeksforgeeks";
    int n = s.length();
    replaceOriginal(s, n);
 
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to reverse order of vowels
#include<bits/stdc++.h>
using namespace std;
 
// utility function to check for vowel
bool isVowel(char c)
{
    return (c=='a' || c=='A' || c=='e' ||
            c=='E' || c=='i' || c=='I' ||
            c=='o' || c=='O' || c=='u' ||
            c=='U');
}
 
// Function to reverse order of vowels
string reverseVowel(string str)
{
    int j=0;
    // Storing the vowels separately
    string vowel;
    for (int i=0; str[i]!='\0'; i++)
        if (isVowel(str[i]))
            vowel[j++] = str[i];
 
    // Placing the vowels in the reverse
    // order in the string
    for (int i=0; str[i]!='\0'; i++)
        if (isVowel(str[i]))
            str[i] = vowel[--j] ;
 
    return str;
}
 
// Driver function
int main()
{
    string str = "hello world";
    cout << reverseVowel(str);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to reverse order of vowels
#include<bits/stdc++.h>
using namespace std;
 
// utility function to check for vowel
bool isVowel(char c)
{
    return (c=='a' || c=='A' || c=='e' ||
            c=='E' || c=='i' || c=='I' ||
            c=='o' || c=='O' || c=='u' ||
            c=='U');
}
 
// Function to reverse order of vowels
string reverseVowel(string str)
{
    // Start two indexes from two corners
    // and move toward each other
    int i = 0;
    int j = str.length()-1;
    while (i < j)
    {
        if (!isVowel(str[i]))
        {
            i++;
            continue;
        }
        if (!isVowel(str[j]))
        {
            j--;
            continue;
        }
 
        // swapping
        swap(str[i], str[j]);
 
        i++;
        j--;
    }
 
    return str;
}
 
// Driver function
int main()
{
    string str = "hello world";
    cout << reverseVowel(str);
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to reverse string
// according to the number of words
#include <bits/stdc++.h>
using namespace std;
 
// Reverse the letters of the word
void reverse(char str[], int start, int end)
{
 
    // Temporary variable to store character
    char temp;
    while (start <= end)
    {
        // Swapping the first and last character
        temp = str[start];
        str[start] = str[end];
        str[end] = temp;
        start++;
        end--;
    }
}
 
// This function forms the required string
void reverseletter(char str[], int start, int end)
{
    int wstart, wend;
    for (wstart = wend = start; wend < end; wend++)
    {
        if (str[wend] == ' ')
            continue;
             
        // Checking the number of words
        // present in string to reverse
        while (str[wend] != ' ' && wend <= end)
            wend++;
        wend--;
         
        // Reverse the letter
        // of the words
        reverse(str, wstart, wend);
    }
}
 
// Driver Code
int main()
{
    char str[1000] = "Ashish Yadav Abhishek Rajput Sunil Pundir";
    reverseletter(str, 0, strlen(str) - 1);
    cout << str;
    return 0;
}
 
// This code is contributed by SHUBHAMSINGH10

Time complexity: linear
Space complexity: constant
// C++ program to reverse each word
// in a linked list
#include <bits/stdc++.h>
using namespace std;
 
// Linked list Node structure
struct Node {
    string c;
    struct Node* next;
};
 
// Function to create newNode
// in a linked list
struct Node* newNode(string c)
{
    Node* temp = new Node;
    temp->c = c;
    temp->next = NULL;
    return temp;
};
 
// reverse each node data
void reverse_word(string& str)
{
    reverse(str.begin(), str.end());
}
 
void reverse(struct Node* head)
{
    struct Node* ptr = head;
 
    // iterate each node and call reverse_word
    // for each node data
    while (ptr != NULL) {
        reverse_word(ptr->c);
        ptr = ptr->next;
    }
}
 
// printing linked list
void printList(struct Node* head)
{
    while (head != NULL) {
        cout << head->c << " ";
        head = head->next;
    }
}
 
// Driver program
int main()
{
    Node* head = newNode("Geeksforgeeks");
    head->next = newNode("a");
    head->next->next = newNode("computer");
    head->next->next->next = newNode("science");
    head->next->next->next->next = newNode("portal");
    head->next->next->next->next->next = newNode("for");
    head->next->next->next->next->next->next = newNode("geeks");
 
    cout << "List before reverse: \n";
    printList(head);
 
    reverse(head);
 
    cout << "\n\nList after reverse: \n";
    printList(head);
 
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to sort an array of strings
// using Trie
#include <bits/stdc++.h>
using namespace std;
 
const int MAX_CHAR = 26;
 
struct Trie {
 
    // index is set when node is a leaf
    // node, otherwise -1;
    int index;
 
    Trie* child[MAX_CHAR];
 
    /*to make new trie*/
    Trie()
    {
        for (int i = 0; i < MAX_CHAR; i++)
            child[i] = NULL;
        index = -1;
    }
};
 
/* function to insert in trie */
void insert(Trie* root, string str, int index)
{
    Trie* node = root;
 
    for (int i = 0; i < str.size(); i++) {
 
        /* taking ascii value to find index of
          child node */
        char ind = str[i] - 'a';
 
        /* making new path if not already */
        if (!node->child[ind])
            node->child[ind] = new Trie();
 
        // go to next node
        node = node->child[ind];
    }
 
    // Mark leaf (end of word) and store
    // index of word in arr[]
    node->index = index;
}
 
/* function for preorder traversal */
bool preorder(Trie* node, string arr[])
{
    if (node == NULL)
        return false;
 
    for (int i = 0; i < MAX_CHAR; i++) {
        if (node->child[i] != NULL) {
 
            /* if leaf node then print key*/
            if (node->child[i]->index != -1)
                cout << arr[node->child[i]->index] << endl;
 
            preorder(node->child[i], arr);
        }
    }
}
 
void printSorted(string arr[], int n)
{
    Trie* root = new Trie();
 
    // insert all keys of dictionary into trie
    for (int i = 0; i < n; i++)
        insert(root, arr[i], i);
 
    // print keys in lexicographic order
    preorder(root, arr);
}
 
// Driver code
int main()
{
    string arr[] = { "abc", "xy", "bcd" };
    int n = sizeof(arr) / sizeof(arr[0]);
    printSorted(arr, n);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to sort a string of characters
#include<bits/stdc++.h>
using namespace std;
 
// function to print string in sorted order
void sortString(string &str)
{
   sort(str.begin(), str.end());
   cout << str;
}
 
// Driver program to test above function
int main()
{
    string s = "geeksforgeeks";
    sortString(s);
    return 0;
}

Time complexity: nlogn
Space complexity: constant
// C++ program to sort a string of characters
#include<bits/stdc++.h>
using namespace std;
 
const int MAX_CHAR = 26;
 
// function to print string in sorted order
void sortString(string &str)
{
    // Hash array to keep count of characters.
    // Initially count of all characters is
    // initialized to zero.
    int charCount[MAX_CHAR] = {0};
     
    // Traverse string and increment
    // count of characters
    for (int i=0; i<str.length(); i++)
 
        // 'a'-'a' will be 0, 'b'-'a' will be 1,
        // so for location of character in count
        // array we will do str[i]-'a'.
        charCount[str[i]-'a']++;   
     
    // Traverse the hash array and print
    // characters
    for (int i=0;i<MAX_CHAR;i++)
        for (int j=0;j<charCount[i];j++)
            cout << (char)('a'+i);
}
 
// Driver program to test above function
int main()
{
    string s = "geeksforgeeks";   
    sortString(s);   
    return 0;
}

Time complexity: linear
Space complexity: constant
// CPP program to sort a string in descending
// order using library function
#include <bits/stdc++.h>
using namespace std;
 
void descOrder(string &s)
{
    sort(s.begin(), s.end(), greater<char>());
}
 
int main()
{
    string s = "geeksforgeeks";
    descOrder(s); // function call
    for(int i = 0; i <  s.size(); i++)
      cout << s[i];
    return 0;
}

Time complexity: constant
Space complexity: constant
// C++ program to sort a string of characters
// in descending order
#include <bits/stdc++.h>
using namespace std;
 
const int MAX_CHAR = 26;
 
// function to print string in sorted order
void sortString(string& str)
{
    // Hash array to keep count of characters.
    // Initially count of all characters is
    // initialized to zero.
    int charCount[MAX_CHAR] = { 0 };
 
    // Traverse string and increment
    // count of characters
    for (int i = 0; i < str.length(); i++)
 
        // 'a'-'a' will be 0, 'b'-'a' will be 1,
        // so for location of character in count
        // array we will do str[i]-'a'.
        charCount[str[i] - 'a']++;
 
    // Traverse the hash array and print
    // characters
    for (int i = MAX_CHAR - 1; i >= 0; i--)
        for (int j = 0; j < charCount[i]; j++)
            cout << (char)('a' + i);
}
 
// Driver program to test above function
int main()
{
    string s = "alkasingh";
    sortString(s);
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ implementation to print array of strings in sorted
// order without copying one string into another
#include <bits/stdc++.h>
 
using namespace std;
 
// function to print strings in sorted order
void printInSortedOrder(string arr[], int n)
{
    int index[n];
    int i, j, min;
     
    // Initially the index of the strings
    // are assigned to the 'index[]'
    for (i=0; i<n; i++)
        index[i] = i;
     
    // selection sort technique is applied   
    for (i=0; i<n-1; i++)   
    {
        min = i;
        for (j=i+1; j<n; j++)
        {
            // with the help of 'index[]'
            // strings are being compared
            if (arr[index[min]].compare(arr[index[j]]) > 0)
                min = j;
        }
         
        // index of the smallest string is placed
        // at the ith index of 'index[]'
        if (min != i)
        {
            int temp = index[min];
            index[min] = index[i];
            index[i] = temp;
        }
    }
     
    // printing strings in sorted order
    for (i=0; i<n; i++)
        cout << arr[index[i]] << " ";
}
 
// Driver program to test above
int main()
{
    string arr[] = {"geeks", "quiz", "geeks", "for"};
    int n = 4;
    printInSortedOrder(arr, n);
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// C++ implementation to sort the given string without
// using any sorting technique
#include <bits/stdc++.h>
using namespace std;
 
// function to sort the given string without
// using any sorting technique
string sortString(string str, int n) {
 
  // to store the final sorted string
  string new_str = "";
 
  // for each character 'i'
  for (int i = 'a'; i <= 'z'; i++)
 
    // if character 'i' is present at a particular
    // index then add character 'i' to 'new_str'
    for (int j = 0; j < n; j++)
      if (str[j] == i)
        new_str += str[j];
 
  // required final sorted string
  return new_str;
}
 
// Driver program to test above
int main() {
  string str = "geeksforgeeks";
  int n = str.size();
  cout << sortString(str, n);
  return 0;
}

Time complexity: linear
Space complexity: constant
// C++ implementation to sort the given
// string without using any sorting technique
#include <iostream>
using namespace std;
 
string sortString(string str, int n) {
int i;
//A character array to store the no.of occurrences of each character
//between 'a' to 'z'
char arr[26]={0};
 
//to store the final sorted string
string new_str = "";
 
//To store each occurrence of character by relative indexing
for (i = 0; i < n; i++)
   ++arr[str[i]-'a'];
 
 
//To traverse the character array and append it to new_str
for(i=0;i<26;i++)
  while(arr[i]--)
    new_str += i+'a';
 
return new_str;
}
 
// Driver program to test above
int main() {
string str = "geeksforgeeks";
int n = str.size();
cout << sortString(str, n);
return 0;
}
 
// This code is contributed by Aravind Alapati

Time complexity: linear
Space complexity: constant
// C++ program for above implementation
#include<bits/stdc++.h>
using namespace std;
const int MAX_CHAR = 26;
 
// Function to return string in lexicographic
// order followed by integers sum
string arrangeString(string str)
{
    int char_count[MAX_CHAR] = {0};
    int sum = 0;
 
    // Traverse the string
    for (int i = 0; i < str.length(); i++)
    {
        // Count occurrence of uppercase alphabets
        if (str[i]>='A' && str[i] <='Z')
            char_count[str[i]-'A']++;
 
        //Store sum of integers
        else
            sum = sum + (str[i]-'0');
    }
 
    string res = "";
 
    // Traverse for all characters A to Z
    for (int i = 0; i < MAX_CHAR; i++)
    {
        char ch = (char)('A'+i);
 
        // Append the current character
        // in the string no. of times it
        //  occurs in the given string
        while (char_count[i]--)
            res = res + ch;
    }
 
    // Append the sum of integers
    if (sum > 0)
        res = res + to_string(sum);
 
    // return resultant string
    return res;
}
 
// Driver program
int main()
{
    string str = "ACCBA10D2EW30";
    cout << arrangeString(str);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to print all permutations
// of a string in sorted order.
#include <bits/stdc++.h>
using namespace std;
 
// Calculating factorial of a number
int factorial(int n)
{
    int f = 1;
    for (int i = 1; i <= n; i++)
        f = f * i;
    return f;
}
 
// Method to find total number of permutations
int calculateTotal(string temp, int n)
{
    int f = factorial(n);
 
    // Building Map to store frequencies of
    // all characters.
    map<char, int> hm;
    for (int i = 0; i < temp.length(); i++)
    {
        hm[temp[i]]++;
    }
 
    // Traversing map and
    // finding duplicate elements.
    for (auto e : hm)
    {
        int x = e.second;
        if (x > 1)
        {
            int temp5 = factorial(x);
            f /= temp5;
        }
        return f;
    }
}
 
static void nextPermutation(string &temp)
{
     
    // Start traversing from the end and
    // find position 'i-1' of the first character
    // which is greater than its successor.
    int i;
    for (i = temp.length() - 1; i > 0; i--)
        if (temp[i] > temp[i - 1]) break;
 
    // Finding smallest character after 'i-1' and
    // greater than temp[i-1]
    int min = i;
    int j, x = temp[i - 1];
    for (j = i + 1; j < temp.length(); j++)
        if ((temp[j] < temp[min]) and
            (temp[j] > x))
            min = j;
 
    // Swapping the above found characters.
    swap(temp[i - 1], temp[min]);
 
    // Sort all digits from position next to 'i-1'
    // to end of the string.
    sort(temp.begin() + i, temp.end());
 
    // Print the String
    cout << temp << endl;
}
 
void printAllPermutations(string s)
{
     
    // Sorting String
    string temp(s);
    sort(temp.begin(), temp.end());
 
    // Print first permutation
    cout << temp << endl;
 
    // Finding the total permutations
    int total = calculateTotal(temp, temp.length());
    for (int i = 1; i < total; i++)
    {
        nextPermutation(temp);
    }
}
 
// Driver Code
int main()
{
    string s = "AAB";
    printAllPermutations(s);
}
 
// This code is contributed by
// sanjeev2552

Time complexity: quadratic
Space complexity: linear