Banana-Leopard/TASTY huggingface dataset:
# A Python program to find last
# index of character x in given
# string.
 
# Returns last index of x if it
# is present. Else returns -1.
def findLastIndex(str, x):
    index = -1
    for i in range(0, len(str)):
        if str[i] == x:
            index = i
    return index
 
# Driver program
 
# String in which char is to be found
str = "geeksforgeeks"
 
# char whose index is to be found
x = 'e'
 
index = findLastIndex(str, x)
 
if index == -1:
    print("Character not found")
else:
    print('Last index is', index)
 
# This code is contributed by shrikant13.

Time complexity: linear
Space complexity: constant
# Simple Python3 program to find last
# index of character x in given string.
 
# Returns last index of x if it is
# present. Else returns -1.
def findLastIndex(str, x):
 
    # Traverse from right
    for i in range(len(str) - 1, -1,-1):
        if (str[i] == x):
            return i
 
    return -1
 
# Driver code
str = "geeksforgeeks"
x = 'e'
index = findLastIndex(str, x)
 
if (index == -1):
    print("Character not found")
else:
    print("Last index is " ,index)
 
# This code is contributed by Smitha

Time complexity: linear
Space complexity: constant
# python program to find position
# of a number in a series of
# numbers with 4 and 7 as the
# only digits.
def findpos(n):
    i = 0
    j = len(n)
    pos = 0
    while (i<j):
         
        # check all digit position
        # if number is left then
        # pos*2+1
        if(n[i] == '4'):
            pos = pos * 2 + 1
             
        # if number is right then
        # pos*2+2
        if(n[i] == '7'):
            pos = pos * 2 + 2
         
        i= i+1
     
    return pos
 
 
# Driver code
# given a number which is constructed
# by 4 and 7 digit only
n = "774"
print(findpos(n))
 
# This code is contributed by Sam007

Time complexity: linear
Space complexity: constant
# Python3 program to find winner in an election.
from collections import defaultdict
 
''' We have four Candidates with name as 'John',
'Johnny', 'jamie', 'jackie'.
The votes in String array are as per the
votes casted. Print the name of candidates
received Max vote. '''
 
 
def findWinner(votes):
 
    # Insert all votes in a hashmap
    mapObj = defaultdict(int)
 
    for st in votes:
        mapObj[st] += 1
 
    # Traverse through map to find the
    # candidate with maximum votes.
    maxValueInMap = 0
    winner = ""
 
    for entry in mapObj:
        key = entry
        val = mapObj[entry]
 
        if (val > maxValueInMap):
            maxValueInMap = val
            winner = key
 
        # If there is a tie, pick lexicographically
        # smaller.
        else if (val == maxValueInMap and
                 winner > key):
            winner = key
 
    print(winner)
 
 
# Driver code
if __name__ == "__main__":
 
    votes = ["john", "johnny", "jackie",
             "johnny", "john", "jackie",
             "jamie", "jamie", "john",
             "johnny", "jamie", "johnny",
             "john"]
 
    findWinner(votes)
 
# This code is contributed by ukasp

Time complexity: linear
Space complexity: linear
# Python 3 program to check if a query
# string is present is given set.
MAX_CHAR = 256
 
def isPresent(s, q):
 
    # Count occurrences of all characters
    # in s.
    freq = [0] *  MAX_CHAR
    for i in range(0 , len(s)):
        freq[ord(s[i])] += 1
 
    # Check if number of occurrences of
    # every character in q is less than
    # or equal to that in s.
    for i in range(0, len(q)):
        freq[ord(q[i])] -= 1
        if (freq[ord(q[i])] < 0):
            return False
     
    return True
 
# driver program
s = "abctd"
q = "cat"
 
if (isPresent(s, q)):
    print("Yes")
else:
    print("No")
 
# This code is contributed by Smitha

Time complexity: linear
Space complexity: constant
# Python program to find
# the arrangement of
# queue at time = t
 
# prints the arrangement
# at time = t
def solve(n, t, p) :
     
    s = list(p)
     
    # Checking the entire
    # queue for every
    # moment from time = 1
    # to time = t.
    for i in range(0, t) :
     
        for j in range(0, n - 1) :    
         
            # If current index
            # contains 'B' and
            # next index contains
            # 'G' then swap
            if (s[j] == 'B' and
                s[j + 1] == 'G') :
                 
                temp = s[j];
                s[j] = s[j + 1];
                s[j + 1] = temp;
                j = j + 1   
                 
    print (''.join(s))
 
# Driver code
n = 6
t = 2
p = "BBGBBG"
solve(n, t, p)
 
# This code is contributed by
# Manish Shaw(manishshaw1)

Time complexity: quadratic
Space complexity: constant
# Python3 code to check whether the
# given EMEI number is valid or not
 
# Function for finding and returning
# sum of digits of a number
def sumDig( n ):
    a = 0
    while n > 0:
        a = a + n % 10
        n = int(n / 10)
 
    return a
 
# Returns True if n is valid EMEI
def isValidEMEI(n):
 
    # Converting the number into
    # String for finding length
    s = str(n)
    l = len(s)
 
    # If length is not 15 then IMEI is Invalid
    if l != 15:
        return False
 
    d = 0
    sum = 0
    for i in range(15, 0, -1):
        d = (int)(n % 10)
        if i % 2 == 0:
 
            # Doubling every alternate digit
            d = 2 * d
 
        # Finding sum of the digits
        sum = sum + sumDig(d)
        n = n / 10
    return (sum % 10 == 0)
 
# Driver code
n = 490154203237518
if isValidEMEI(n):
    print("Valid IMEI Code")
else:
    print("Invalid IMEI Code")
 
# This code is contributed by "Sharad_Bhardwaj".

Time complexity: nlogn
Space complexity: linear
# Python3 program to decode a median
# string to the original string
 
# function to calculate the median
# back string
def decodeMedianString(s):
     
    # length of string
    l = len(s)
 
    # initialize a blank string
    s1 = ""
 
    # Flag to check if length is
    # even or odd
    if(l % 2 == 0):
        isEven = True
    else:
        isEven = False
 
    # traverse from first to last
    for i in range(0, l, 2):
         
        # if len is even then add first
        # character to beginning of new
        # string and second character to end
        if (isEven):
            s1 = s[i] + s1
            s1 += s[i + 1]
        else :
             
            # if current length is odd and
            # is greater than 1
            if (l - i > 1):
                 
                # add first character to end and
                # second character to beginning
                s1 += s[i]
                s1 = s[i + 1] + s1
            else:
                 
                # if length is 1, add character
                # to end
                s1 += s[i]
 
    return s1
 
# Driver Code
if __name__ == '__main__':
    s = "eekgs"
    print(decodeMedianString(s))
 
# This code is contributed by
# Sanjit_Prasad

Time complexity: linear
Space complexity: constant
# Python 3 program to make a number magical
  
# function to calculate the minimal changes
def calculate( s):
 
    # maximum digits that can be changed
    ans = 6
  
    # nested loops to generate all 6
    # digit numbers
    for i in range(10):
        for j in range(10):
            for k in range(10):
                for l in range(10):
                    for  m in range(10):
                        for n in range(10):
                            if (i + j + k == l + m + n):
                                  
                                # counter to count the number
                                # of change required
                                c = 0
                                  
                                # if first digit is equal
                                if (i != ord(s[0]) - ord('0')):
                                    c+=1
                                      
                                # if 2nd digit is equal   
                                if (j != ord(s[1]) - ord('0')):
                                    c+=1
                                  
                                # if 3rd digit is equal   
                                if (k != ord(s[2]) - ord('0')):
                                    c+=1
                                  
                                # if 4th digit is equal   
                                if (l != ord(s[3]) - ord('0')):
                                    c+=1
                                      
                                # if 5th digit is equal   
                                if (m != ord(s[4]) - ord('0')):
                                    c+=1
                                      
                                # if 6th digit is equal   
                                if (n != ord(s[5]) - ord('0')):
                                    c+=1
  
                                # checks if less than the
                                # previous calculate changes
                                if (c < ans):
                                    ans = c
      
    # returns the answer
    return ans
  
# driver program to test the above function
if __name__ == "__main__":
     
    # number stored in string
    s = "123456"
  
    # prints the minimum operations
    print(calculate(s))

Time complexity: np
Space complexity: constant
# Python code to check if a
# given ISBN is valid or not.
 
def isValidISBN(isbn):
 
    # check for length
    if len(isbn) != 10:
        return False
     
    # Computing weighted sum
    # of first 9 digits
    _sum = 0
    for i in range(9):
        if 0 <= int(isbn[i]) <= 9:
            _sum += int(isbn[i]) * (10 - i)
        else:
            return False
         
    # Checking last digit
    if(isbn[9] != 'X' and
       0 <= int(isbn[9]) <= 9):
        return False
     
    # If last digit is 'X', add
    # 10 to sum, else add its value.
    _sum += 10 if isbn[9] == 'X' else int(isbn[9])
     
    # Return true if weighted sum of
    # digits is divisible by 11
    return (_sum % 11 == 0)
 
# Driver Code
isbn = "007462542X"
if isValidISBN(isbn):
    print('Valid')
else:
    print("Invalid")
     
# This code is contributed
# by "Abhishek Sharma 44"

Time complexity: constant
Space complexity: constant
class CreditCard:
    # Main Method
    @staticmethod
    def main(args):
        number = 5196081888500645
        print(str(number) + " is " +
              ("valid" if CreditCard.isValid(number) else "invalid"))
         
    # Return true if the card number is valid
    @staticmethod
    def isValid(number):
        return (CreditCard.getSize(number) >= 13 and CreditCard.getSize(number) <= 16) and (CreditCard.prefixMatched(number, 4) or CreditCard.prefixMatched(number, 5) or CreditCard.prefixMatched(number, 37) or CreditCard.prefixMatched(number, 6)) and ((CreditCard.sumOfDoubleEvenPlace(number) + CreditCard.sumOfOddPlace(number)) % 10 == 0)
     
    # Get the result from Step 2
    @staticmethod
    def sumOfDoubleEvenPlace(number):
        sum = 0
        num = str(number) + ""
        i = CreditCard.getSize(number) - 2
        while (i >= 0):
            sum += CreditCard.getDigit(int(str(num[i]) + "") * 2)
            i -= 2
        return sum
       
    # Return this number if it is a single digit, otherwise,
    # return the sum of the two digits
    @staticmethod
    def getDigit(number):
        if (number < 9):
            return number
        return int(number / 10) + number % 10
       
    # Return sum of odd-place digits in number
    @staticmethod
    def sumOfOddPlace(number):
        sum = 0
        num = str(number) + ""
        i = CreditCard.getSize(number) - 1
        while (i >= 0):
            sum += int(str(num[i]) + "")
            i -= 2
        return sum
       
    # Return true if the digit d is a prefix for number
    @staticmethod
    def prefixMatched(number,  d):
        return CreditCard.getPrefix(number, CreditCard.getSize(d)) == d
       
    # Return the number of digits in d
    @staticmethod
    def getSize(d):
        num = str(d) + ""
        return len(num)
       
    # Return the first k number of digits from
    # number. If the number of digits in number
    # is less than k, return number.
    @staticmethod
    def getPrefix(number,  k):
        if (CreditCard.getSize(number) > k):
            num = str(number) + ""
            return int(num[0:k])
        return number
 
if __name__ == "__main__":
    CreditCard.main([])
 
# This code is contributed by Aarti_Rathi

Time complexity: linear
Space complexity: constant
# Python3 program to implement the approach
 
# Python3 has no built-in swap function.
def swap(str, i, j):
    ch = list(str)
    temp = ch[i]
    ch[i] = ch[j]
    ch[j] = temp
    return "".join(ch)
 
# Since STRINGS are immutable in JavaScript, first we have
# to convert it to a character array in order to sort.
def sortString(str, s_index, e_index):
    tempArray = list(str)
 
    # Sorting temp array using
    tempArray = tempArray[:s_index] + sorted(tempArray[s_index: e_index])
 
    # returning the new sorted string
    return "".join(tempArray)
 
def maximizeNumber(N, M):
    # Sorting the digits of the
    # number in increasing order.
    N = sortString(N, 0, len(N))
 
    for i in range(len(N)):
        for j in range(i + 1, len(N)):
 
            # Copying the string into another
            # temp string.
            t = N
 
            # Swapping the j-th char(digit)
            # with i-th char(digit)
 
            t = swap(t, j, i)
 
            # Sorting the temp string
            # from i-th pos to end.
            t = sortString(t, i + 1, len(t))
 
            # Checking if the string t is
            # greater than string N and less
            # than or equal to the number M.
            if (int(t) > int(N) and int(t) <= M):
 
                # If yes then, we will permanently
                # swap the i-th char(or digit)
                # with j-th char(digit).
                N = swap(N, i, j)
 
    # Returns the maximized number.
    return N
 
# Driver Code
N = "123"
M = 222
print(maximizeNumber(N, M))
 
# This code is contributed by phasing17

Time complexity: cubic
Space complexity: linear
# Python program to find
# if a given corner string
# is present at corners.
 
def isCornerPresent(str, corner) :
 
    n = len(str)
    cl = len(corner)
 
    # If length of corner
    # string is more, it
    # cannot be present
    # at corners.
    if (n < cl) :
        return False
 
    # Return true if corner
    # string is present at
    # both corners of given
    # string.
    return ((str[: cl] == corner) and
            (str[n - cl :] == corner))
 
# Driver Code
str = "geeksforgeeks"
corner = "geeks"
if (isCornerPresent(str, corner)) :
    print ("Yes")
else :
    print ("No")
 
# This code is contributed by
# Manish Shaw(manishshaw1)

Time complexity: linear
Space complexity: constant