Banana-Leopard/TASTY huggingface dataset:
# Python3 program to reverse order of vowels
 
# utility function to check for vowel
def isVowel(c):
    if (c == 'a' or c == 'A' or c == 'e' or
        c == 'E' or c == 'i' or c == 'I' or
        c == 'o' or c == 'O' or c == 'u' or c == 'U'):
        return True
    return False
 
# Function to reverse order of vowels
def reverserVowel(string):
    j = 0
    vowel = [0] * len(string)
    string = list(string)
 
    # Storing the vowels separately
    for i in range(len(string)):
        if isVowel(string[i]):
            vowel[j] = string[i]
            j += 1
 
    # Placing the vowels in the reverse
    # order in the string
    for i in range(len(string)):
        if isVowel(string[i]):
            j -= 1
            string[i] = vowel[j]
 
    return ''.join(string)
 
# Driver Code
if __name__ == "__main__":
    string = "hello world"
    print(reverserVowel(string))
 
# This code is contributed by
# sanjeev2552

Time complexity: linear
Space complexity: linear
# Python3 program to reverse order of vowels
 
# utility function to check for vowel
def isVowel(c):
    return (c=='a' or c=='A' or c=='e' or
            c=='E' or c=='i' or c=='I' or
            c=='o' or c=='O' or c=='u' or
            c=='U')
 
# Function to reverse order of vowels
def reverseVowel(str):
 
    # Start two indexes from two corners
    # and move toward each other
    i = 0
    j = len(str) - 1
    while (i < j):
        if not isVowel(str[i]):
            i += 1
            continue
        if (not isVowel(str[j])):
            j -= 1
            continue
         
        # swapping
        str[i], str[j] = str[j], str[i]
        i += 1
        j -= 1
    return str
 
# Driver function
if __name__ == "__main__":
    str = "hello world"
    print(*reverseVowel(list(str)), sep = "")
 
# This code is contributed by SHUBHAMSINGH10

Time complexity: linear
Space complexity: constant
# Python3 program to reverse string
# according to the number of words
 
# Reverse the letters of the word
def reverse(string, start, end):
 
    # Temporary variable to store character
    temp = ''
    while start <= end:
 
        # Swapping the first and last character
        temp = string[start]
        string[start] = string[end]
        string[end] = temp
        start += 1
        end -= 1
 
# This function forms the required string
def reverseletter(string, start, end):
    wstart, wend = start, start
 
    while wend < end:
        if string[wend] == " ":
            wend += 1
            continue
 
        # Checking the number of words
        # present in string to reverse
        while wend <= end and string[wend] != " ":
            wend += 1
        wend -= 1
 
        # Reverse the letter
        # of the words
        reverse(string, wstart, wend)
        wend += 1
 
# Driver Code
if __name__ == "__main__":
    string = "Ashish Yadav Abhishek Rajput Sunil Pundir"
    string = list(string)
    reverseletter(string, 0, len(string) - 1)
    print(''.join(string))
 
# This code is contributed by
# sanjeev2552

Time complexity: linear
Space complexity: constant
# Python3 program to reverse each word
# in a linked list
 
# Node of a linked list
class Node:
    def __init__(self, next = None, data = None):
        self.next = next
        self.data = data
 
# Function to create newNode
# in a linked list
def newNode(c) :
 
    temp = Node()
    temp.c = c
    temp.next = None
    return temp
 
# reverse each node data
def reverse_word(str) :
    s = ""
    i = 0
    while(i < len(str) ):
        s = str[i] + s
        i = i + 1
    return s
 
def reverse( head) :
    ptr = head
 
    # iterate each node and call reverse_word
    # for each node data
    while (ptr != None):
        ptr.c = reverse_word(ptr.c)
        ptr = ptr.next
     
    return head
 
# printing linked list
def printList( head) :
 
    while (head != None):
        print( head.c ,end = " ")
        head = head.next
     
# Driver program
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")
 
print( "List before reverse: ")
printList(head)
 
head = reverse(head)
 
print( "\n\nList after reverse: ")
printList(head)
 
# This code is contributed by Arnab Kundu

Time complexity: linear
Space complexity: constant
# Python3 program to sort an Array of
# Strings according to their lengths
 
# Function to print the sorted array of string
def printArraystring(string, n):
    for i in range(n):
        print(string[i], end = " ")
 
# Function to Sort the array of string
# according to lengths. This function
# implements Insertion Sort.
def sort(s, n):
    for i in range(1, n):
        temp = s[i]
 
        # Insert s[j] at its correct position
        j = i - 1
        while j >= 0 and len(temp) < len(s[j]):
            s[j + 1] = s[j]
            j -= 1
 
        s[j + 1] = temp
 
# Driver code
if __name__ == "__main__":
    arr = ["GeeksforGeeks", "I", "from", "am"]
    n = len(arr)
 
    # Function to perform sorting
    sort(arr, n)
 
    # Calling the function to print result
    printArraystring(arr, n)
 
# This code is contributed by
# sanjeev2552

Time complexity: quadratic
Space complexity: constant
from functools import cmp_to_key
 
# Function to check the small string
def compare(s1,s2):
    return len(s1) - len(s2)
 
# Function to print the sorted array of string
def printArraystring(str,n):
    for i in range(n):
        print(str[i],end = " ")
 
# Driver function
arr = ["GeeksforGeeks", "I", "from", "am"]
n = len(arr)
 
# Function to perform sorting
arr.sort(key = cmp_to_key(compare))
 
# Calling the function to print result
printArraystring(arr, n)
 
# This code is contributed by shinjanpatra.

Time complexity: nlogn
Space complexity: constant
# Python code for the above approach
def printsorted(arr):
   
    # Sorting using sorted function
    # providing key as len
    print(*sorted(arr, key=len))
 
 
# Driver code
arr = ["GeeksforGeeks", "I", "from", "am"]
 
# Passing list to printsorted function
printsorted(arr)
 
# this code is contributed by vikkycirus

Time complexity: nlogn
Space complexity: constant
# Python3 program to sort an array of strings
# using Trie
 
MAX_CHAR = 26
 
class Trie:
 
    # index is set when node is a leaf
    # node, otherwise -1;
    # to make new trie
    def __init__(self):
        self.child = [None for i in range(MAX_CHAR)]
        self.index = -1
     
 
# def to insert in trie
def insert(root,str,index):
 
    node = root
 
    for i in range(len(str)):
 
        # taking ascii value to find index of
        # child node
        ind = ord(str[i]) - ord('a')
 
        # making new path if not already
        if (node.child[ind] == None):
            node.child[ind] = 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
def preorder(node, arr):
 
    if (node == None):
        return False
 
    for i in range(MAX_CHAR):
        if (node.child[i] != None):
 
            # if leaf node then print key
            if (node.child[i].index != -1):
                print(arr[node.child[i].index])
 
            preorder(node.child[i], arr)
         
 
 
def printSorted(arr,n):
 
    root = Trie()
 
    # insert all keys of dictionary into trie
    for i in range(n):
        insert(root, arr[i], i)
 
    # print keys in lexicographic order
    preorder(root, arr)
 
 
# Driver code
 
arr = [ "abc", "xy", "bcd" ]
n = len(arr)
printSorted(arr, n)
 
# This code is contributed by shinjanpatra

Time complexity: linear
Space complexity: linear
# Python3 program to sort a string
# of characters
 
# function to print string in
# sorted order
def sortString(str) :
    str = ''.join(sorted(str))
    print(str)
 
# Driver Code
s = "geeksforgeeks"
sortString(s)
 
# This code is contributed by Smitha

Time complexity: nlogn
Space complexity: constant
# Python 3 program to sort a string
# of characters
 
MAX_CHAR = 26
 
# function to print string in sorted order
def sortString(str):
     
    # Hash array to keep count of characters.
    # Initially count of all characters is
    # initialized to zero.
    charCount = [0 for i in range(MAX_CHAR)]
     
    # Traverse string and increment
    # count of characters
    for i in range(0, len(str), 1):
         
        # '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[ord(str[i]) - ord('a')] += 1
     
    # Traverse the hash array and print
    # characters
    for i in range(0, MAX_CHAR, 1):
        for j in range(0, charCount[i], 1):
            print(chr(ord('a') + i), end = "")
 
# Driver Code
if __name__ == '__main__':
    s = "geeksforgeeks"
    sortString(s)
     
# This code is contributed by
# Sahil_Shelangia

Time complexity: linear
Space complexity: constant
# Python program to sort
# a string in descending
# order using library function
 
def descOrder(s):
    s.sort(reverse = True)
    str1 = ''.join(s)
    print(str1)
 
def main():
    s = list('geeksforgeeks')
     
    # function call
    descOrder(s)
 
if __name__=="__main__":
    main()
 
# This code is contributed by
# prabhat kumar singh

Time complexity: constant
Space complexity: constant
# Python program to sort a string of characters
# in descending order
 
MAX_CHAR = 26;
 
# function to print string in sorted order
def sortString(str):
     
    # Hash array to keep count of characters.
    # Initially count of all charters is
    # initialized to zero.
    charCount = [0]*MAX_CHAR;
 
    # Traverse string and increment
    # count of characters
    for i in range(len(str)):
 
        # '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[ord(str[i]) - ord('a')]+=1;
 
    # Traverse the hash array and print
    # characters
    for i in range(MAX_CHAR - 1,-1, -1):
        for j in range(charCount[i]):
            print(chr(97+i),end="");
 
# Driver program to test above function
s = "alkasingh";
sortString(s);
 
# This code is contributed by Princi Singh

Time complexity: linear
Space complexity: constant
# Python 3 implementation to print array
# of strings in sorted order without
# copying one string into another
 
# function to print strings in sorted order
def printInSortedOrder(arr, n):
    index = [0] * n
     
    # Initially the index of the strings
    # are assigned to the 'index[]'
    for i in range(n):
        index[i] = i
     
    # selection sort technique is applied
    for i in range(n - 1):
        min = i
        for j in range(i + 1, n):
             
            # with the help of 'index[]'
            # strings are being compared
            if (arr[index[min]] > arr[index[j]]):
                min = j
         
        # index of the smallest string is placed
        # at the ith index of 'index[]'
        if (min != i):
            index[min], index[i] = index[i], index[min]
     
    # printing strings in sorted order
    for i in range(n):
        print(arr[index[i]], end = " ")
 
# Driver Code
if __name__ == "__main__":
     
    arr = ["geeks", "quiz", "geeks", "for"]
    n = 4
    printInSortedOrder(arr, n)
 
# This code is contributed by ita_c

Time complexity: quadratic
Space complexity: linear
# Python3 implementation to sort
# the given string without using
# any sorting technique
 
# Function to sort the given string
# without using any sorting technique
def sortString(str, n):
 
    # To store the final sorted string
    new_str = ""
 
    # for each character 'i'
    for i in range(ord('a'), ord('z') + 1):
 
        # if character 'i' is present at a particular
        # index then add character 'i' to 'new_str'
        for j in range(n):
            if (str[j] == chr(i)):
                new_str += str[j]
 
    # required final sorted string
    return new_str
 
# Driver Code
str = "geeksforgeeks"
n = len(str)
print(sortString(str, n))
 
# This code is contributed by Anant Agarwal.

Time complexity: linear
Space complexity: constant
# Python 3 implementation to sort the given
# string without using any sorting technique
def sortString(st, n):
   
    # A character array to store the no.of occurrences of each character
    # between 'a' to 'z'
    arr = [0] * 26
 
    # to store the final sorted string
    new_str = ""
     
    # To store each occurrence of character by relative indexing
    for i in range(n):
        arr[ord(st[i]) - ord('a')] += 1
 
    # To traverse the character array and append it to new_str
    for i in range(26):
        while(arr[i] > 0):
            new_str += chr(i+ord('a'))
            arr[i] -= 1
 
    return new_str
 
# Driver program to test above
if __name__ == "__main__":
 
    st = "geeksforgeeks"
    n = len(st)
    print(sortString(st, n))
 
    # This code is contributed by ukasp.

Time complexity: linear
Space complexity: constant
# Python3 program for above implementation
MAX_CHAR = 26
 
# Function to return string in lexicographic
# order followed by integers sum
def arrangeString(string):
    char_count = [0] * MAX_CHAR
    s = 0
 
    # Traverse the string
    for i in range(len(string)):
 
        # Count occurrence of uppercase alphabets
        if string[i] >= "A" and string[i] <= "Z":
            char_count[ord(string[i]) - ord("A")] += 1
 
        # Store sum of integers
        else:
            s += ord(string[i]) - ord("0")
 
    res = ""
 
    # Traverse for all characters A to Z
    for i in range(MAX_CHAR):
        ch = chr(ord("A") + i)
 
        # Append the current character
        # in the string no. of times it
        # occurs in the given string
        while char_count[i]:
            res += ch
            char_count[i] -= 1
 
    # Append the sum of integers
    if s > 0:
        res += str(s)
 
    # return resultant string
    return res
 
# Driver code
if __name__ == "__main__":
    string = "ACCBA10D2EW30"
    print(arrangeString(string))
 
# This code is contributed by
# sanjeev2552

Time complexity: linear
Space complexity: linear
# Python3 program to print
# all permutations of a
# string in sorted order.
from collections import defaultdict
 
# Calculating factorial
# of a number
def factorial(n):
 
    f = 1
     
    for i in range (1, n + 1):
        f = f * i
    return f
 
# Method to find total
# number of permutations
def calculateTotal(temp, n):
 
    f = factorial(n)
 
    # Building Map to store
    # frequencies of all
    # characters.
    hm = defaultdict (int)
     
    for i in range (len(temp)):
        hm[temp[i]] += 1
    
    # Traversing map and
    # finding duplicate elements.
    for e in hm:
        x = hm[e]
        if (x > 1):
            temp5 = factorial(x)
            f //= temp5
        return f
 
def nextPermutation(temp):
     
    # Start traversing from
    # the end and find position
    # 'i-1' of the first character
    # which is greater than its successor
    for i in range (len(temp) - 1, 0, -1):
        if (temp[i] > temp[i - 1]):
            break
 
    # Finding smallest character
    # after 'i-1' and greater
    # than temp[i-1]
    min = i
    x = temp[i - 1]
    for j in range (i + 1, len(temp)):
        if ((temp[j] < temp[min]) and
            (temp[j] > x)):
            min = j
 
    # Swapping the above
    # found characters.
    temp[i - 1], temp[min] = (temp[min],
                              temp[i - 1])
 
    # Sort all digits from
    # position next to 'i-1'
    # to end of the string
    temp[i:].sort()
 
    # Print the String
    print (''.join(temp))
 
def printAllPermutations(s):
     
    # Sorting String
    temp = list(s)
    temp.sort()
 
    # Print first permutation
    print (''.join( temp))
 
    # Finding the total permutations
    total = calculateTotal(temp,
                           len(temp))
    for i in range (1, total):
        nextPermutation(temp)
 
# Driver Code
if __name__ == "__main__":
 
    s = "AAB"
    printAllPermutations(s)
 
# This code is contributed by Chitranayal

Time complexity: quadratic
Space complexity: linear
# Python program to get minimum cost to sort
# strings by reversal operation
 
# Returns minimum cost for sorting arr[]
# using reverse operation. This function
# returns -1 if it is not possible to sort.
def ReverseStringMin(arr, reverseCost, n):
     
    # dp[i][j] represents the minimum cost to
    # make first i strings sorted.
    # j = 1 means i'th string is reversed.
    # j = 0 means i'th string is not reversed.
     
    dp = [[float("Inf")] * 2 for i in range(n)]
 
    # initializing dp array for first string
    dp[0][0] = 0
 
    dp[0][1] = reverseCost[0]
 
    # getting array of reversed strings
    rev_arr = [i[::-1] for i in arr]
 
    # looping for all strings
    for i in range(1, n):
 
        # Looping twice, once for string and once
        # for reversed string
        for j in range(2):
 
            # getting current string and current
            # cost according to j
            curStr = arr[i] if j==0 else rev_arr[i]
 
            curCost = 0 if j==0 else reverseCost[i]
 
            # Update dp value only if current string
            # is lexicographically larger
            if (curStr >= arr[i - 1]):
 
                dp[i][j] = min(dp[i][j], dp[i-1][0] + curCost)
 
            if (curStr >= rev_arr[i - 1]):
 
                dp[i][j] = min(dp[i][j], dp[i-1][1] + curCost)
 
    # getting minimum from both entries of last index
    res = min(dp[n-1][0], dp[n-1][1])
 
    return res if res != float("Inf") else -1
 
 
# Driver code
def main():
 
 
    arr = ["aa", "ba", "ac"]
 
    reverseCost = [1, 3, 1]
 
    n = len(arr)
 
    dp = [float("Inf")] * n
 
    res = ReverseStringMin(arr, reverseCost,n)
 
    if res != -1 :
 
        print ("Minimum cost to sort sorting is" , res)
 
    else :
        print ("Sorting not possible")
 
 
if __name__ == '__main__':
    main()
 
#This code is contributed by Neelam Yadav

Time complexity: linear
Space complexity: linear
# Python program for printing
# all numbers containing 1,2 and 3
 
 
def printNumbers(numbers):
 
    # convert all numbers
    # to strings
    numbers = map(str, numbers)
    result = []
    for num in numbers:
 
        # check if each number
        # in the list has 1,2 and 3
        if ('1' in num and
            '2' in num and
                '3' in num):
            result.append(num)
 
    # if there are no
    # valid numbers
    if not result:
        result = ['-1']
 
    return sorted(result)
 
 
# Driver Code
numbers = [123, 1232, 456,
           234, 32145]
result = printNumbers(numbers)
print ', '.join(num for num in result)
 
# This code is contributed
# by IshitaTripathi

Time complexity: nlogn
Space complexity: linear
# Python3 program to implement binary search
#  in a sparse array
 
def sparseSearch(arr , key , low , high):
 
    left = 0; right = 0
 
    while low <= high:
 
            mid = low + (high - low) // 2
 
            if arr[mid] == '':
                left = mid - 1
                right = mid + 1
 
                while True:
 
                    # Check for out of bounds
                    if left < low and right > high:
                        return -1
 
                    elif left >= low and arr[left] != '':
                        # Search left
                        mid = left
                        break
 
                    elif right <= high and arr[right] != '':
                        # Search right
                        mid = right
                        break
 
                    left -= 1
                    right += 1
 
            if arr[mid] == key:
                print('Found string {} at index {}'.format
                     (arr[mid] , mid))
                return mid
 
            # Classical Binary search
            # search left
            elif arr[mid] > key:
                high = mid - 1
 
            # search right
            elif arr[mid] < key:
                low = mid + 1
 
    return -1
 
if __name__ == '__main__':
 
    arr = ["for", "geeks", "", "", "", "", "ide",
           "practice", "", "", "", "quiz"]                
    key = 'geeks'
 
    low = 0
    high = len(arr) - 1
 
    sparseSearch(arr , key , low , high)
 
# This is  Code contributed by
# Ashwin Viswanathan
# Additional Updates by Meghna Natraj

Time complexity: logn
Space complexity: logn
# Python3 Program to find maximum
# lowercase alphabets present
# between two uppercase alphabets
 
MAX_CHAR = 26
 
# Function which computes the
# maximum number of distinct
# lowercase alphabets between
# two uppercase alphabets
def maxLower(str):
    n = len(str)
 
    # Ignoring lowercase characters
    # in the beginning.
    i = 0
    for i in range(n):
        if str[i] >= 'A' and str[i] <= 'Z':
            i += 1
            break
             
    # We start from next of first capital
    # letter and traverse through
    # remaining character.
    maxCount = 0
    count = []
    for j in range(MAX_CHAR):
        count.append(0)
         
    for j in range(i, n):
 
        # If character is in uppercase,
        if str[j] >= 'A' and str[j] <= 'Z':
 
            # Count all distinct lower
            # case characters
            currCount = 0
            for k in range(MAX_CHAR):
                if count[k] > 0:
                    currCount += 1
 
            # Update maximum count
            maxCount = max(maxCount, currCount)
 
            # Reset count array
            for y in count:
                y = 0
                 
        # If character is in lowercase
        if str[j] >= 'a' and str[j] <= 'z':
            count[ord(str[j]) - ord('a')] += 1
             
    return maxCount
 
# Driver function
str = "zACaAbbaazzC";
print(maxLower(str))
 
# This code is contributed by Upendra Bartwal

Time complexity: linear
Space complexity: constant
# Python3 Program to find maximum
# lowercase alphabets present
# between two uppercase alphabets
 
# Function which computes the
# maximum number of distinct
# lowercase alphabets between
# two uppercase alphabets
def maxLower(str):
   
    n = len(str);
 
    # Ignoring lowercase characters
    # in the beginning.
    i = 0;
    for i in range(n):
       
        if (str[i] >= 'A' and
            str[i] <= 'Z'):
            i += 1;
            break;
 
    # We start from next of first
    # capital letter and traverse
    # through remaining character.
    maxCount = 3;
    s = set()
     
    for i in range(n):
 
        # If character is in
        # uppercase,
        if (str[i] >= 'A' and
            str[i] <= 'Z'):
           
            # Update maximum count if
            # lowercase character before
            # this is more.
            maxCount = max(maxCount,
                           len(s));
             
            # clear the set
            s.clear();
 
        # If character is in
        # lowercase
        if (str[i] >= 'a' and
            str[i] <= 'z'):
            s.add(str[i]);
            return maxCount;
 
# Driver Code
if __name__ == '__main__':
   
    str = "zACaAbbaazzC";
    print(maxLower(str));
 
# This code is contributed by 29AjayKumar

Time complexity: linear
Space complexity: linear
# Python3 program to Convert characters
# of a string to opposite case
 
str = "GeEkSfOrGeEkS"
x=""
for i in str:
    if(i.isupper()):
        x+=i.lower()
    else:
        x+=i.upper()
print(x)

Time complexity: linear
Space complexity: constant
# Python3 program to Convert characters
# of a string to opposite case
 
str = "GeEkSfOrGeEkS"
x=""
upperalphabets="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
loweralphabets="abcdefghijklmnopqrstuvwxyz"
for i in str:
    if i in upperalphabets:
        x+=loweralphabets[upperalphabets.index(i)]
    else:
        x+=upperalphabets[loweralphabets.index(i)]
print(x)

Time complexity: linear
Space complexity: constant