Banana-Leopard/TASTY huggingface dataset:
# Python3 program to convert a
# sentence to gOOGLE cASE.
def convert(str):
   
    # empty strings
    w = ""
    z = "";
 
    # convert input string
    # to upper case
    str = str.upper() + " ";
 
    for i in range(len(str)):
 
        # checki if character is not
        # a space and adding it to
        # string w
        ch = str[i];
        if (ch != ' '):
            w = w + ch;
        else:
 
            # converting first character
            # to lower case and subsequent
            # initial letter of another
            # word to lower case
            z = (z + (w[0]).lower() +
                 w[1:len(w)] + " ");
            w = "";
 
    return z;
 
# Driver code
if __name__ == '__main__':
   
    str = "I got intern at geeksforgeeks";
    print(convert(str));
 
# This code is contributed by 29AjayKumar

Time complexity: linear
Space complexity: linear
# Python program to convert given
# sentence to camel case.
import math
 
# Function to remove spaces
# and convert into camel case
def convert( s):
 
        n = len(s)
        s1 = ""
        s1 = s1 + s[0].lower()
        i = 1
        while i < n:
            # check for spaces in the sentence
            if (s[i] == ' ' and i <= n):
             
                # conversion into upper case
                s1 = s1 + " " + (s[i + 1]).lower()
                i = i + 1
                 
            # If not space, copy character
            else:
                s1 = s1 + (s[i]).upper()
             
            # increase index of string by s1
            i = i + 1
         
        # return string to main
        return s1
     
# Driver code
str = "I get intern at geeksforgeeks"
print(convert(str))
 
# This code is contributed by Gitanjali.

Time complexity: linear
Space complexity: constant
# Python program to convert
# given sentence to camel case.
 
# Function to remove spaces
# and convert into camel case
def convert(s):
    if(len(s) == 0):
        return
    s1 = ''
    s1 += s[0].upper()
    for i in range(1, len(s)):
        if (s[i] == ' '):
            s1 += s[i + 1].upper()
            i += 1
        elif(s[i - 1] != ' '):
            s1 += s[i]
    print(s1)    
             
 
# Driver Code
def main():
    s = "I get intern at geeksforgeeks"
    convert(s)
     
if __name__=="__main__":
    main()
     
# This code is contributed
# prabhat kumar singh
    

Time complexity: linear
Space complexity: constant
# Python code to print all permutations
# with respect to cases
 
# function to generate permutations
 
 
def permute(ip, op):
 
    #  base case
    if len(ip) == 0:
        print(op, end=" ")
        return
 
    #  pick lower and uppercase
    ch = ip[0].lower()
    ch2 = ip[0].upper()
    ip = ip[1:]
    permute(ip, op+ch)
    permute(ip, op+ch2)
 
# driver code
 
 
def main():
    ip = "AB"
    permute(ip, "")
 
 
main()
 
# This Code is Contributed by Vivek Maddeshiya

Time complexity: np
Space complexity: linear
# Python code to print all permutations
# with respect to cases
 
# Function to generate permutations
 
 
def permute(inp):
    n = len(inp)
 
    # Number of permutations is 2^n
    mx = 1 << n
 
    # Converting string to lower case
    inp = inp.lower()
 
    # Using all subsequences and permuting them
    for i in range(mx):
        # If j-th bit is set, we convert it to upper case
        combination = [k for k in inp]
        for j in range(n):
            if (((i >> j) & 1) == 1):
                combination[j] = inp[j].upper()
 
        temp = ""
        # Printing current combination
        for i in combination:
            temp += i
        print temp,
 
 
# Driver code
permute("ABC")
 
# This code is contributed by Sachin Bisht

Time complexity: quadratic
Space complexity: linear
# Python3 program to get toggle case of a string
x = 32;
 
# tOGGLE cASE = swaps CAPS to lower
# case and lower case to CAPS
def toggleCase(a):
 
    for i in range(len(a)):
 
        # Bitwise EXOR with 32
        a = a[:i] + chr(ord(a[i]) ^ 32) + a[i + 1:];
    return a;
 
# Driver Code
str = "CheRrY";
print("Toggle case: ", end = "");
str = toggleCase(str);
print(str);
 
print("Original string: ", end = "");
str = toggleCase(str);
print(str);
 
# This code is contributed by 29AjayKumar

Time complexity: linear
Space complexity: constant
# Python program to print the first non-repeating character
 
string = "geeksforgeeks"
index = -1
fnc = ""
for i in string:
    if string.count(i) == 1:
        fnc += i
        break
    else:
        index += 1
if index == 1:
    print("Either all characters are repeating or string is empty")
else:
    print("First non-repeating character is", fnc)

Time complexity: quadratic
Space complexity: constant
# python3 implementation
 
 
def FirstNonRepeat(s):
 
    for i in s:
 
        if (s.find(i, (s.find(i)+1))) == -1:
 
            print("First non-repeating character is", i)
 
            break
 
    return
 
# __main__
 
 
s = 'geeksforgeeks'
 
FirstNonRepeat(s)

Time complexity: quadratic
Space complexity: constant
# Python program to print the first non-repeating character
NO_OF_CHARS = 256
 
# Returns an array of size 256 containing count
# of characters in the passed char array
 
 
def getCharCountArray(string):
    count = [0] * NO_OF_CHARS
    for i in string:
        count[ord(i)] += 1
    return count
 
# The function returns index of first non-repeating
# character in a string. If all characters are repeating
# then returns -1
 
 
def firstNonRepeating(string):
    count = getCharCountArray(string)
    index = -1
    k = 0
 
    for i in string:
        if count[ord(i)] == 1:
            index = k
            break
        k += 1
 
    return index
 
 
# Driver program to test above function
string = "geeksforgeeks"
index = firstNonRepeating(string)
if index == 1:
    print("Either all characters are repeating or string is empty")
else:
    print("First non-repeating character is", string[index])
 
# This code is contributed by Bhavya Jain

Time complexity: linear
Space complexity: constant
# Python3 program to find first non-repeating
# character
import sys
 
NO_OF_CHARS = 256
 
#    The function returns index of the first
#    non-repeating character in a string. If
#    all characters are repeating then
#    returns sys.maxsize :
 
 
def firstNonRepeating(Str):
 
    arr = [[] for i in range(NO_OF_CHARS)]
    for i in range(NO_OF_CHARS):
        arr[i] = [0, 0]
 
    for i in range(len(Str)):
        arr[ord(Str[i])][0] += 1
        arr[ord(Str[i])][1] = i
 
    res = sys.maxsize
    for i in range(NO_OF_CHARS):
 
        # If this character occurs only
        # once and appears before the
        # current result, then update the
        # result
        if (arr[i][0] == 1):
            res = min(res, arr[i][1])
 
    return res
 
 
# Driver program to test above functionS
Str = "geeksforgeeks"
index = firstNonRepeating(Str)
if (index == sys.maxsize):
    print("Either all characters are repeating or string is empty")
else:
    print("First non-repeating character is ", Str[index])
 
# This code is contributed by shinjanpatra

Time complexity: linear
Space complexity: constant
# this function return the index of first non-repeating
# character if found, or else it returns -1
import sys
 
 
def firstNonRepeating(Str):
    fi = [-1 for i in range(256)]
 
    # sets all repeating characters to -2 and non-repeating characters
    # contain the index where they occur
    for i in range(len(Str)):
 
        if(fi[ord(Str[i])] == -1):
            fi[ord(Str[i])] = i
        else:
            fi[ord(Str[i])] = -2
 
    res = sys.maxsize
 
    for i in range(256):
 
        # If this character is not -1 or -2 then it
        # means that this character occurred only once
        # so find the min index of all characters that
        # occur only once, that's our first index
        if(fi[i] >= 0):
            res = min(res, fi[i])
 
    # if res remains INT_MAX, it means there are no
    # characters that repeat only once or the string is empty
    if(res == sys.maxsize):
        return -1
    else:
        return res
 
 
Str = "geeksforgeeks"
firstIndex = firstNonRepeating(Str)
 
if (firstIndex == -1):
    print("Either all characters are repeating or string is empty")
else:
    print("First non-repeating character is " + str(Str[firstIndex]))
 
# This code is contributed by shinjanpatra

Time complexity: linear
Space complexity: constant
# Python implementation
from collections import Counter
 
# Function which repeats
# first Nonrepeating character
 
 
def printNonrepeated(string):
 
    # Calculating frequencies
    # using Counter function
    freq = Counter(string)
 
    # Traverse the string
    for i in string:
        if(freq[i] == 1):
            print("First non-repeating character is " + i)
            break
 
 
# Driver code
string = "geeksforgeeks"
 
# passing string to printNonrepeated function
printNonrepeated(string)
 
# this code is contributed by vikkycirus

Time complexity: linear
Space complexity: constant
# Python program to print all permutations with repetition
# of characters
 
def toString(List):
    return ''.join(List)
 
# The main function that recursively prints all repeated
# permutations of the given string. It uses data[] to store
# all permutations one by one
def allLexicographicRecur (string, data, last, index):
    length = len(string)
 
    # One by one fix all characters at the given index and
    # recur for the subsequent indexes
    for i in range(length):
 
        # Fix the ith character at index and if this is not
        # the last index then recursively call for higher
        # indexes
        data[index] = string[i]
 
        # If this is the last index then print the string
        # stored in data[]
        if index==last:
            print (toString(data))
        else:
            allLexicographicRecur(string, data, last, index+1)
 
# This function sorts input string, allocate memory for data
# (needed for allLexicographicRecur()) and calls
# allLexicographicRecur() for printing all permutations
def allLexicographic(string):
    length = len(string)
 
    # Create a temp array that will be used by
    # allLexicographicRecur()
    data = [""] * (length+1)
 
    # Sort the input string so that we get all output strings in
    # lexicographically sorted order
    string = sorted(string)
 
    # Now print all permutations
    allLexicographicRecur(string, data, length-1, 0)
 
# Driver program to test the above functions
string = "ABC"
print ("All permutations with repetition of " + string + " are:")
allLexicographic(string)
 
# This code is contributed to Bhavya Jain

Time complexity: np
Space complexity: linear
# A Python program to find first non-repeating character from
# a stream of characters
MAX_CHAR = 256
 
def findFirstNonRepeating():
 
    # inDLL[x] contains pointer to a DLL node if x is present
    # in DLL. If x is not present, then inDLL[x] is NULL
    inDLL = [] * MAX_CHAR
 
    # repeated[x] is true if x is repeated two or more times.
    # If x is not seen so far or x is seen only once. then
    # repeated[x] is false
    repeated = [False] * MAX_CHAR
 
    # Let us consider following stream and see the process
    stream = "geekforgeekandgeeksandquizfor"
    for i in range(len(stream)):
        x = stream[i]
        print ("Reading " + x + " from stream")
 
        # We process this character only if it has not occurred
        # or occurred only once. repeated[x] is true if x is
        # repeated twice or more.s
        if not repeated[ord(x)]:
 
            # If the character is not in DLL, then add this
            # at the end of DLL
            if not x in inDLL:
                inDLL.append(x)
            else:
                inDLL.remove(x)
                repeated[ord(x)] = True
 
        if len(inDLL) != 0:
            print ("First non-repeating character so far is ")
            print (str(inDLL[0]))
 
# Driver program
findFirstNonRepeating()
 
# This code is contributed by BHAVYA JAIN

Time complexity: linear
Space complexity: constant
# Python3 program to check if a can be converted to
# a that has repeated subs of length k.
 
# Returns True if S can be converted to a
# with k repeated subs after replacing k
# characters.
def check( S, k):
     
    # Length of must be a multiple of k
    n = len(S)
     
    if (n % k != 0):
        return False
 
    # Map to store s of length k and their counts
    mp =  {}
    for i in range(0, n, k):
        mp[S[i:k]] = mp.get(S[i:k], 0) + 1
 
    # If is already a repetition of k subs,
    # return True.
    if (len(mp) == 1):
        return True
 
    # If number of distinct subs is not 2, then
    # not possible to replace a .
    if (len(mp) != 2):
        return False
 
    # One of the two distinct must appear exactly once.
    # Either the first entry appears once, or it appears
    # n/k-1 times to make other sub appear once.
    for i in mp:
        if i == (n//k - 1) or mp[i] == 1:
            return True
 
    return False
 
# Driver code
 
if check("abababcd", 2):
    print("Yes")
else:
    print("No")
     
# This code is contributed by mohit kumar 29   

Time complexity: linear
Space complexity: linear
# Python3 program to find smallest possible
# length of a string of only three characters
 
# A memoized function find result recursively.
# a, b and c are counts of 'a's, 'b's and
# 'c's in str
def length(a, b, c):
     
    global DP
     
    #print(a, b, c)
     
    # If this subproblem is already
    # evaluated
    if a < 0 or b < 0 or c < 0:
        return 0
 
    if (DP[a][b] != -1):
        return DP[a][b]
 
    # If there is only one type
    # of character
    if (a == 0 and b == 0):
        DP[a][b] = c
        return c
    if (a == 0 and c == 0):
        DP[a][b] = b
        return b
    if (b == 0 and c == 0):
        DP[a][b] = a
        return a
 
    # If only two types of characters
    # are present
    if (a == 0):
        DP[a][b] = length(a + 1, b - 1,
                             c - 1)
        return DP[a][b]
         
    if (b == 0):
        DP[a][b] = length(a - 1, b + 1,
                             c - 1)
        return DP[a][b]
         
    if (c == 0):
        DP[a][b] = length(a - 1, b - 1,
                             c + 1)
        return DP[a][b]
 
    # If all types of characters are present.
    # Try combining all pairs.
    x = length(a - 1, b - 1, c + 1)
    y = length(a - 1, b + 1, c - 1)
    z = length(a + 1, b - 1, c - 1)
 
    DP[a][b] = min([x, y, z])
 
    return DP[a][b]
 
# Returns smallest possible length with
# given operation allowed.
def stringReduction(str):
     
    n = len(str)
 
    # Counting occurrences of three different
    # characters 'a', 'b' and 'c' in str
    count = [0] * 3
     
    for i in range(n):
        count[ord(str[i]) - ord('a')] += 1
 
    return length(count[0], count[1], count[2])
     
# Driver code
if __name__ == '__main__':
     
    DP = [[[-1 for i in range(110)]
               for i in range(110)]
               for i in range(110)]
 
    str = "abcbbaacb"
     
    print(stringReduction(str))
 
# This code is contributed by mohit kumar 29

Time complexity: linear
Space complexity: linear
# Python3 program to find smallest possible
# length of a string of only three characters
 
# Returns smallest possible length
# with given operation allowed.
def stringReduction(str):
 
    n = len(str)
 
    # Counint occurrences of three different
    # characters 'a', 'b' and 'c' in str
    count = [0] * 3
    for i in range(n):
        count[ord(str[i]) - ord('a')] += 1
 
    # If all characters are same.
    if (count[0] == n or count[1] == n or
                         count[2] == n):
        return n
 
    # If all characters are present even number
    # of times or all are present odd number of
    # times.
    if ((count[0] % 2) == (count[1] % 2) and
        (count[1] % 2) == (count[2] % 2)):
        return 2
 
    # Answer is 1 for all other cases.
    return 1
 
# Driver code
if __name__ == "__main__":
     
    str = "abcbbaacb"
    print(stringReduction(str))
 
# This code is contributed by ita_c

Time complexity: linear
Space complexity: constant
# Python3 program to find if its possible to
# distribute balls without repetition
 
 
MAX_CHAR = 26
 
# function to find if its possible to
# distribute balls or not
def distributingBalls(k, n, string) :
 
    # count array to count how many times
    # each color has occurred
    a = [0] * MAX_CHAR
     
    for i in range(n) :
        # increasing count of each color
        # every time it appears
        a[ord(string[i]) - ord('a')] += 1
     
    for i in range(MAX_CHAR) :
        # to check if any color appears
        # more than K times if it does
        # we will print NO
        if (a[i] > k) :
            return False
     
    return True
 
 
# Driver code
if __name__ == "__main__" :
  
    n, k = 6, 3
    string = "aacaab"
 
    if (distributingBalls(k, n, string)) :
        print("YES")
    else :
        print("NO")
 
# This code is contributed by Ryuga

Time complexity: linear
Space complexity: constant
# Python 3 program to find the
# maximum consecutive repeating
# character in given string
 
# function to find out the maximum
# repeating character in given string
def maxRepeating(str):
 
    l = len(str)
    count = 0
 
    # Find the maximum repeating
    # character starting from str[i]
    res = str[0]
    for i in range(l):
         
        cur_count = 1
        for j in range(i + 1, l):
     
            if (str[i] != str[j]):
                break
            cur_count += 1
 
        # Update result if required
        if cur_count > count :
            count = cur_count
            res = str[i]
    return res
 
# Driver code
if __name__ == "__main__":
 
    str = "aaaabbaaccde"
    print(maxRepeating(str))
 
# This code is contributed
# by ChitraNayal

Time complexity: quadratic
Space complexity: constant
# Python 3 program to find the
# maximum consecutive repeating
# character in given string
 
# Returns the maximum repeating
# character in a given string
def maxRepeating(str):
 
    n = len(str)
    count = 0
    res = str[0]
    cur_count = 1
 
    # Traverse string except
    # last character
    for i in range(n):
         
        # If current character
        # matches with next
        if (i < n - 1 and
            str[i] == str[i + 1]):
            cur_count += 1
 
        # If doesn't match, update result
        # (if required) and reset count
        else:
            if cur_count > count:
                count = cur_count
                res = str[i]
            cur_count = 1
    return res
 
# Driver code
if __name__ == "__main__":
    str = "aaaabbaaccde"
    print(maxRepeating(str))
 
# This code is contributed
# by ChitraNayal

Time complexity: linear
Space complexity: constant
# Python 3 program to find k'th
# non-repeating character in a string
MAX_CHAR = 256
 
# Returns index of k'th non-repeating
# character in given string str[]
def kthNonRepeating(str, k):
 
    n = len(str)
 
    # count[x] is going to store count of 
    # character 'x' in str. If x is not
    # present, then it is going to store 0.
    count = [0] * MAX_CHAR
 
    # index[x] is going to store index of
    # character 'x' in str. If x is not
    # present or x is repeating, then it
    # is going to store a value (for example,
    # length of string) that cannot be a valid
    # index in str[]
    index = [0] * MAX_CHAR
 
    # Initialize counts of all characters
    # and indexes of non-repeating characters.
    for i in range( MAX_CHAR):
        count[i] = 0
        index[i] = n # A value more than any
                     # index in str[]
 
    # Traverse the input string
    for i in range(n):
         
        # Find current character and
        # increment its count
        x = str[i]
        count[ord(x)] += 1
 
        # If this is first occurrence, then
        # set value in index as index of it.
        if (count[ord(x)] == 1):
            index[ord(x)] = i
 
        # If character repeats, then remove
        # it from index[]
        if (count[ord(x)] == 2):
            index[ord(x)] = n
 
    # Sort index[] in increasing order. This step
    # takes O(1) time as size of index is 256 only
    index.sort()
 
    # After sorting, if index[k-1] is value,
    # then return it, else return -1.
    return index[k - 1] if (index[k - 1] != n) else -1
 
# Driver code
if __name__ == "__main__":
    str = "geeksforgeeks"
    k = 3
    res = kthNonRepeating(str, k)
    if(res == -1):
        print("There are less than k",
              "non-repeating characters")
    else:
        print("k'th non-repeating character is",
                                       str[res])
 
# This code is contributed
# by ChitraNayal

Time complexity: nlogn
Space complexity: linear
MAX_CHAR = 256
 
def kthNonRepeating(Input,k):
    inputLength = len(Input)
     
    # indexArr will store index of non-repeating characters,
    # inputLength for characters not in input and
    # inputLength+1 for repeated characters.
     
    # initialize all values in indexArr as inputLength.
    indexArr = [inputLength for i in range(MAX_CHAR)]
     
    for i in range(inputLength):
        c = Input[i]
        if (indexArr[ord(c)] == inputLength):
            indexArr[ord(c)] = i
        else:
            indexArr[ord(c)] = inputLength + 2
    indexArr.sort()
    if(indexArr[k - 1] != inputLength):
        return indexArr[k - 1]
    else:
        return -1
 
Input = "geeksforgeeks"
k = 3
res = kthNonRepeating(Input, k)
if(res == -1):
    print("There are less than k non-repeating characters")
else:
    print("k'th non-repeating character is", Input[res])
     
# This code is contributed by rag2127

Time complexity: nlogn
Space complexity: linear
# Python3 program to find the first
# character that is repeated
 
def findRepeatFirstN2(s):
 
    # this is O(N^2) method
    p = -1
    for i in range(len(s)):
     
        for j in range (i + 1, len(s)):
         
            if (s[i] == s[j]):
                p = i
                break
             
        if (p != -1):
            break
 
    return p
 
# Driver code
if __name__ == "__main__":
 
    str = "geeksforgeeks"
    pos = findRepeatFirstN2(str)
    if (pos == -1):
        print ("Not found")
    else:
        print (str[pos])
     
# This code is contributed
# by ChitraNayal

Time complexity: quadratic
Space complexity: constant
# Python 3 program to find the first
# character that is repeated
 
# 256 is taken just to ensure nothing
# is left, actual max ASCII limit is 128
 
MAX_CHAR = 256
 
def findRepeatFirst(s):
     
    # this is optimized method
    p = -1
 
    # initialized counts of occurrences
    # of elements as zero
    hash = [0 for i in range(MAX_CHAR)]
 
    # initialized positions
    pos = [0 for i in range(MAX_CHAR)]
 
    for i in range(len(s)):
        k = ord(s[i])
        if (hash[k] == 0):
            hash[k] += 1
            pos[k] = i
        elif(hash[k] == 1):
            hash[k] += 1
 
    for i in range(MAX_CHAR):
        if (hash[i] == 2):
            if (p == -1): # base case
                p = pos[i]
            elif(p > pos[i]):
                p = pos[i]
    return p
 
# Driver code
if __name__ == '__main__':
    str = "geeksforgeeks"
    pos = findRepeatFirst(str);
    if (pos == -1):
        print("Not found")
    else:
        print(str[pos])
         
# This code is contributed by
# Shashank_Sharma

Time complexity: linear
Space complexity: constant
# Python implementation
from collections import Counter
 
# Function which repeats
# first repeating character
def printrepeated(string):
   
    # Calculating frequencies
    # using Counter function
    freq = Counter(string)
     
    # Traverse the string
    for i in string:
        if(freq[i] > 1):
            print(i)
            break
 
 
# Driver code
string = "geeksforgeeks"
 
# passing string to printrepeated function
printrepeated(string)
 
# this code is contributed by vikkycirus

Time complexity: linear
Space complexity: linear