Banana-Leopard/TASTY huggingface dataset:
# Python3 program to convert fractional
# decimal to binary number
 
# Function to convert decimal to binary
# upto k-precision after decimal point
def decimalToBinary(num, k_prec) :
 
    binary = ""
 
    # Fetch the integral part of
    # decimal number
    Integral = int(num)
 
    # Fetch the fractional part
    # decimal number
    fractional = num - Integral
 
    # Conversion of integral part to
    # binary equivalent
    while (Integral) :
         
        rem = Integral % 2
 
        # Append 0 in binary
        binary += str(rem);
 
        Integral //= 2
     
    # Reverse string to get original
    # binary equivalent
    binary = binary[ : : -1]
 
    # Append point before conversion
    # of fractional part
    binary += '.'
 
    # Conversion of fractional part
    # to binary equivalent
    while (k_prec) :
         
        # Find next bit in fraction
        fractional *= 2
        fract_bit = int(fractional)
 
        if (fract_bit == 1) :
             
            fractional -= fract_bit
            binary += '1'
             
        else :
            binary += '0'
 
        k_prec -= 1
 
    return binary
 
# Driver code
if __name__ == "__main__" :
     
    n = 4.47
    k = 3
    print(decimalToBinary(n, k))
 
    n = 6.986
    k = 5
    print(decimalToBinary(n, k))
 
# This code is contributed by Ryuga

Time complexity: linear
Space complexity: linear
# Python3 implementation to convert
# a sentence into its equivalent
# mobile numeric keypad sequence
 
# Function which computes the
# sequence
 
 
def printSequence(arr, input):
 
    # length of input string
    n = len(input)
    output = ""
 
    for i in range(n):
 
        # checking for space
        if(input[i] == ' '):
            output = output + "0"
        else:
            # calculating index for each
            # character
            position = ord(input[i]) - ord('A')
            output = output + arr[position]
    # output sequence
    return output
 
 
# Driver code
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"]
 
input = "GEEKSFORGEEKS"
print(printSequence(str, input))
 
# This code is contributed by upendra bartwal

Time complexity: linear
Space complexity: linear
# Python Program for above implementation
 
# Function to check is it possible to convert
# first string into another string or not.
def isItPossible(str1, str2, m, 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 str1.count('A') != str2.count('A') \
    or str1.count('B') != str2.count('B'):
        return False
 
    # Start traversing
    for i in range(m):
        if (str1[i] != '#'):
            for j in range(n):
                # To Check no two elements cross each other.
                if ((str2[j] != str1[i]) and 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' and i < j):
                        return False
 
                    # To Check Is it Possible to Move
                    # towards Right or not.
                    if (str1[i] == 'B' and i > j):
                        return False
 
                    break
                 
    return True
 
# Drivers code
 
str1 = "A#B#"
str2 = "A##B"
 
m = len(str1)
n = len(str2)
 
str1 = list(str1)
str2 = list(str2)
 
if(isItPossible(str1, str2, m, n)):
    print("Yes")
else:
    print("No")
 
# This code is contributed by ankush_953

Time complexity: quadratic
Space complexity: linear
# Python 3 Program to convert str1 to
# str2 in exactly k operations
 
# Returns true if it is possible to convert
# str1 to str2 using k operations.
def isConvertible(str1, str2, k):
     
    # Case A (i)
    if ((len(str1) + len(str2)) < k):
        return True
 
    # finding common length of both string
    commonLength = 0
    for i in range(0, min(len(str1),
                          len(str2)), 1):
        if (str1[i] == str2[i]):
            commonLength += 1
        else:
            break
 
    # Case A (ii)-
    if ((k - len(str1) - len(str2) + 2 *
                commonLength) % 2 == 0):
        return True
 
    # Case B-
    return False
 
# Driver Code
if __name__ == '__main__':
    str1 = "geek"
    str2 = "geek"
    k = 7
    if (isConvertible(str1, str2, k)):
        print("Yes")
    else:
        print("No")
 
    str1 = "geeks"
    str2 = "geek"
    k = 5
    if (isConvertible(str1, str2, k)):
        print("Yes")
    else:
        print("No")
 
# This code is contributed by
# Sanjit_Prasad

Time complexity: linear
Space complexity: constant
# Python3 program to convert
# decimal number to roman numerals
 
ls=[1000,900,500,400,100,90,50,40,10,9,5,4,1]
dict={1:"I",4:"IV",5:"V",9:"IX",10:"X",40:"XL",50:"L",90:"XC",100:"C",400:"CD",500:"D",900:"CM",1000:"M"}
ls2=[]
 
# Function to convert decimal to Roman Numerals
def func(no,res):
    for i in range(0,len(ls)):
        if no in ls:
            res=dict[no]
            rem=0
            break
        if ls[i]<no:
            quo=no//ls[i]
            rem=no%ls[i]
            res=res+dict[ls[i]]*quo
            break
    ls2.append(res)
    if rem==0:
        pass
    else:
        func(rem,"")
 
 
# Driver code
if __name__ == "__main__":
    func(3549, "")
    print("".join(ls2))
 
# This code is contributed by
# VIKAS CHOUDHARY(vikaschoudhary344)

Time complexity: linear
Space complexity: constant
# Python3 program for above approach
 
# Function to calculate roman equivalent
 
 
def intToRoman(num):
 
    # Storing roman values of digits from 0-9
    # when placed at different places
    m = ["", "M", "MM", "MMM"]
    c = ["", "C", "CC", "CCC", "CD", "D",
         "DC", "DCC", "DCCC", "CM "]
    x = ["", "X", "XX", "XXX", "XL", "L",
         "LX", "LXX", "LXXX", "XC"]
    i = ["", "I", "II", "III", "IV", "V",
         "VI", "VII", "VIII", "IX"]
 
    # Converting to roman
    thousands = m[num // 1000]
    hundreds = c[(num % 1000) // 100]
    tens = x[(num % 100) // 10]
    ones = i[num % 10]
 
    ans = (thousands + hundreds +
           tens + ones)
 
    return ans
 
 
# Driver code
if __name__ == "__main__":
 
    number = 3549
 
    print(intToRoman(number))
 
# This code is contributed by rutvik_56

Time complexity: linear
Space complexity: constant
# Python 3 program to convert Decimal
# number to Roman numbers.
import math
 
def integerToRoman(A):
    romansDict = \
        {
            1: "I",
            5: "V",
            10: "X",
            50: "L",
            100: "C",
            500: "D",
            1000: "M",
            5000: "G",
            10000: "H"
        }
 
    div = 1
    while A >= div:
        div *= 10
 
    div //= 10
 
    res = ""
 
    while A:
 
        # main significant digit extracted
        # into lastNum
        lastNum = (A // div)
 
        if lastNum <= 3:
            res += (romansDict[div] * lastNum)
        elif lastNum == 4:
            res += (romansDict[div] +
                          romansDict[div * 5])
        elif 5 <= lastNum <= 8:
            res += (romansDict[div * 5] +
            (romansDict[div] * (lastNum - 5)))
        elif lastNum == 9:
            res += (romansDict[div] +
                         romansDict[div * 10])
 
        A = math.floor(A % div)
        div //= 10
         
    return res
 
# Driver code
print("Roman Numeral of Integer is:"
                   + str(integerToRoman(3549)))

Time complexity: linear
Space complexity: constant
# Python program to convert Roman Numerals
# to Numbers
 
# This function returns value of each Roman symbol
 
 
def value(r):
    if (r == 'I'):
        return 1
    if (r == 'V'):
        return 5
    if (r == 'X'):
        return 10
    if (r == 'L'):
        return 50
    if (r == 'C'):
        return 100
    if (r == 'D'):
        return 500
    if (r == 'M'):
        return 1000
    return -1
 
 
def romanToDecimal(str):
    res = 0
    i = 0
 
    while (i < len(str)):
 
        # Getting value of symbol s[i]
        s1 = value(str[i])
 
        if (i + 1 < len(str)):
 
            # Getting value of symbol s[i + 1]
            s2 = value(str[i + 1])
 
            # Comparing both values
            if (s1 >= s2):
 
                # Value of current symbol is greater
                # or equal to the next symbol
                res = res + s1
                i = i + 1
            else:
 
                # Value of current symbol is greater
                # or equal to the next symbol
                res = res + s2 - s1
                i = i + 2
        else:
            res = res + s1
            i = i + 1
 
    return res
 
 
# Driver code
print("Integer form of Roman Numeral is"),
print(romanToDecimal("MCMIV"))

Time complexity: linear
Space complexity: constant
# Program to convert Roman
# Numerals to Numbers
roman = {}
roman['I'] = 1
roman['V'] = 5
roman['X'] = 10
roman['L'] = 50
roman['C'] = 100
roman['D'] = 500
roman['M'] = 1000
     
# This function returns value
# of a Roman symbol
def romanToInt(s):
   sum = 0
   n = len(s)
 
   i = 0
   while i < n :
 
      # If present value is less than next value,
      # subtract present from next value and add the
      # resultant to the sum variable.
      # print(roman[s[i]],roman[s[i+1]])
      if (i != n - 1 and roman[s[i]] < roman[s[i + 1]]):
         sum += roman[s[i + 1]] - roman[s[i]]
         i += 2
         continue
      else:
         sum += roman[s[i]]
      i += 1
   return sum
 
# Driver Code
     
# Considering inputs given are valid
input = "MCMIV"
 
print(f"Integer form of Roman Numeral is {romanToInt(input)}")
 
# This code is contributed by shinjanpatra

Time complexity: constant
Space complexity: constant
def romanToInt(s):
        translations = {
            "I": 1,
            "V": 5,
            "X": 10,
            "L": 50,
            "C": 100,
            "D": 500,
            "M": 1000
        }
        number = 0
        s = s.replace("IV", "IIII").replace("IX", "VIIII")
        s = s.replace("XL", "XXXX").replace("XC", "LXXXX")
        s = s.replace("CD", "CCCC").replace("CM", "DCCCC")
        for char in s:
            number += translations[char]
        print(number)
         
romanToInt('MCMIV')

Time complexity: constant
Space complexity: constant
# Python3 program to check if a string can
# be converted to another string by
# performing operations
 
 
# function to check if a string can be
# converted to another string by
# performing following operations
def check(s1,s2):
     
    # calculates length
    n = len(s1)
    m = len(s2)
    dp=([[False for i in range(m+1)]
       for i in range(n+1)])
     
    # mark 1st position as true
    dp[0][0] = True
     
    # traverse for all DPi, j
    for i in range(len(s1)):
        for j in range(len(s2)+1):
             
            # 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 < len(s2) and
                   (s1[i].upper()== s2[j]))):
                    dp[i + 1][j + 1] = True
                     
                # if not upper then deletion is
                # possible
                if (s1[i].isupper()==False):
                    dp[i + 1][j] = True
    return (dp[n][m])
 
# driver code
if __name__=='__main__':
 
    s1 = "daBcd"
    s2 = "ABC"
    if (check(s1, s2)):
        print("YES")
    else:
        print("NO")
 
# this code is contributed by
# sahilshelangia

Time complexity: quadratic
Space complexity: quadratic
# Python code to
# transform string
 
# def to change
# character's case
def change_case(s) :
     
    a = list(s)
    l = len(s)
     
    for i in range(0, l) :
     
        # If character is
        # lowercase change
        # to uppercase
        if(a[i] >= 'a' and
           a[i] <= 'z') :
            a[i] = s[i].upper()
             
        # If character is uppercase
        # change to lowercase
        elif(a[i] >= 'A' and
             a[i] <= 'Z') :
            a[i] = s[i].lower()
 
    return a
 
# def to delete vowels
def delete_vowels(s) :
 
    temp = ""
    a = list(s)
    l = len(s)
    for i in range(0, l) :
     
        # If character
        # is consonant
        if(a[i] != 'a' and a[i] != 'e' and
           a[i] != 'i' and a[i] != 'o' and
           a[i] != 'u' and a[i] != 'A' and
           a[i] != 'E' and a[i] != 'O' and
           a[i] != 'U' and a[i] != 'I') :
            temp = temp + a[i]
 
    return temp
 
# def to insert "#"
def insert_hash(s) :
 
    temp = ""
    a = list(s)
    l = len(s)
     
    for i in range(0, l) :
     
        # If character is
        # not special
        if((a[i] >= 'a' and
            a[i] <= 'z') or
        (a[i] >= 'A' and
            a[i] <= 'Z')) :
            temp = temp + '#' + a[i]
        else :
            temp = temp + a[i]
     
    return temp
 
# def to
# transform string
def transformSting(a) :
 
    b = delete_vowels(a)
    c = change_case(b)
    d = insert_hash(c)
 
    print (d)
 
# Driver Code
a = "SunshinE!!"
 
# Calling def
transformSting(a)
 
# This code is contributed by
# Manish Shaw(manishshaw1)

Time complexity: linear
Space complexity: linear
# Python implementation of above approach
 
# A utility function to reverse string str[low..high]
def Reverse(string: list, low: int, high: int):
    while low < high:
        string[low], string[high] = string[high], string[low]
        low += 1
        high -= 1
 
# Cycle leader algorithm to move all even
# positioned elements at the end.
def cycleLeader(string: list, shift: int, len: int):
    i = 1
    while i < len:
        j = i
        item = string[j + shift]
 
        while True:
 
            # odd index
            if j & 1:
                j = len // 2 + j // 2
 
            # even index
            else:
                j //= 2
 
            # keep the back-up of element at new position
            string[j + shift], item = item, string[j + shift]
 
            if j == i:
                break
        i *= 3
 
# The main function to transform a string. This function
# mainly uses cycleLeader() to transform
def moveNumberToSecondHalf(string: list):
    k, lenFirst = 0, 0
    lenRemaining = len(string)
    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 += 1
        lenFirst = pow(3, k - 1) + 1
        lenRemaining -= lenFirst
 
        # Step 2: Apply cycle leader algorithm
        # for the largest subarrau
        cycleLeader(string, shift, lenFirst)
 
        # Step 4.1: Reverse the second half of first subarray
        Reverse(string, shift // 2, shift - 1)
 
        # Step 4.2: Reverse the first half of second sub-string
        Reverse(string, 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(string, shift // 2, shift + lenFirst // 2 - 1)
 
        # Increase the length of first subarray
        shift += lenFirst
 
# Driver Code
if __name__ == "__main__":
 
    string = "a1b2c3d4e5f6g7"
    string = list(string)
    moveNumberToSecondHalf(string)
    print(''.join(string))
 
# This code is contributed by
# sanjeev2552

Time complexity: quadratic
Space complexity: constant
# Python3 program to count the distinct
# transformation of one string to other.
 
def countTransformation(a, b):
    n = len(a)
    m = len(b)
 
    # If b = "" i.e., an empty string. There
    # is only one way to transform (remove all
    # characters)
    if m == 0:
        return 1
 
    dp = [[0] * (n) for _ in range(m)]
 
    # Fill dp[][] in bottom up manner
    # Traverse all character of b[]
    for i in range(m):
 
        # Traverse all characters of a[] for b[i]
        for j in range(i, n):
 
            # Filling the first row of the dp
            # matrix.
            if i == 0:
                if j == 0:
                    if a[j] == b[i]:
                        dp[i][j] = 1
                    else:
                        dp[i][j] = 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
if __name__ == "__main__":
    a = "abcccdf"
    b = "abccdf"
    print(countTransformation(a, b))
 
# This code is contributed by vibhu4agarwal

Time complexity: quadratic
Space complexity: quadratic
# Write Python3 code here
# -*- coding: utf-8 -*-
 
# Example Input
s = "*-A/BC-/AKL"
 
# Stack for storing operands
stack = []
 
operators = set(['+', '-', '*', '/', '^'])
 
# Reversing the order
s = s[::-1]
 
# iterating through individual tokens
for i in s:
 
    # if token is operator
    if i in operators:
 
        # pop 2 elements from stack
        a = stack.pop()
        b = stack.pop()
 
        # concatenate them as operand1 +
        # operand2 + operator
        temp = a+b+i
        stack.append(temp)
 
    # else if operand
    else:
        stack.append(i)
 
# printing final output
print(*stack)

Time complexity: linear
Space complexity: linear
# Python3 program to find infix for
# a given postfix.
def isOperand(x):
    return ((x >= 'a' and x <= 'z') or
            (x >= 'A' and x <= 'Z'))
 
# Get Infix for a given postfix
# expression
def getInfix(exp) :
 
    s = []
 
    for i in exp:    
         
        # Push operands
        if (isOperand(i)) :        
            s.insert(0, i)
             
        # We assume that input is a
        # valid postfix and expect
        # an operator.
        else:
         
            op1 = s[0]
            s.pop(0)
            op2 = s[0]
            s.pop(0)
            s.insert(0, "(" + op2 + i +
                             op1 + ")")
             
    # There must be a single element in
    # stack now which is the required
    # infix.
    return s[0]
 
# Driver Code
if __name__ == '__main__':
 
    exp = "ab*c+"
    print(getInfix(exp.strip()))
 
# This code is contributed by
# Shubham Singh(SHUBHAMSINGH10)

Time complexity: linear
Space complexity: linear
# Python 3 program for space optimized
# solution of Word Wrap problem.
import sys
 
# Function to find space optimized
# solution of Word Wrap problem.
def solveWordWrap(arr, n, k):
 
    dp = [0] * n
 
    # Array in which ans[i] store index
    # of last word in line starting with
    # word arr[i].
    ans = [0] * n
 
    # If only one word is present then
    # only one line is required. Cost
    # of last line is zero. Hence cost
    # of this line is zero. Ending point
    # is also n-1 as single word is
    # present.
    dp[n - 1] = 0
    ans[n - 1] = n - 1
 
    # Make each word first word of line
    # by iterating over each index in arr.
    for i in range(n - 2, -1, -1):
        currlen = -1
        dp[i] = sys.maxsize
 
        # Keep on adding words in current
        # line by iterating from starting
        # word upto last word in arr.
        for j in range(i, n):
 
            # Update number of characters
            # in current line. arr[j] is
            # number of characters in
            # current word and 1
            # represents space character
            # between two words.
            currlen += (arr[j] + 1)
 
            # If limit of characters
            # is violated then no more
            # words can be added to
            # current line.
            if (currlen > k):
                break
 
            # If current word that is
            # added to line is last
            # word of arr then current
            # line is last line. Cost of
            # last line is 0. Else cost
            # is square of extra spaces
            # plus cost of putting line
            # breaks in rest of words
            # from j+1 to n-1.
            if (j == n - 1):
                cost = 0
            else:
                cost = ((k - currlen) *
                        (k - currlen) + dp[j + 1])
 
            # Check if this arrangement gives
            # minimum cost for line starting
            # with word arr[i].
            if (cost < dp[i]):
                dp[i] = cost
                ans[i] = j
 
    # Print starting index and ending index
    # of words present in each line.
    i = 0
    while (i < n):
        print(i + 1 , ans[i] + 1, end = " ")
        i = ans[i] + 1
 
# Driver Code
if __name__ == "__main__":
     
    arr = [3, 2, 2, 5 ]
    n = len(arr)
    M = 6
    solveWordWrap(arr, n, M)
 
# This code is contributed by ita_c

Time complexity: quadratic
Space complexity: linear
# Python 3 program to print shortest possible
# path to type all characters of given string
# using a remote
 
# Function to print shortest possible path
# to type all characters of given string
# using a remote
def printPath(str):
    i = 0
     
    # start from character 'A' present
    # at position (0, 0)
    curX = 0
    curY = 0
    while (i < len(str)):
         
        # find coordinates of next character
        nextX = int((ord(str[i]) - ord('A')) / 5)
        nextY = (ord(str[i]) - ord('B') + 1) % 5
 
        # Move Up if destination is above
        while (curX > nextX):
            print("Move Up")
            curX -= 1
 
        # Move Left if destination is to the left
        while (curY > nextY):
            print("Move Left")
            curY -= 1
 
        # Move down if destination is below
        while (curX < nextX):
            print("Move Down")
            curX += 1
 
        # Move Right if destination is to the right
        while (curY < nextY):
            print("Move Right")
            curY += 1
 
        # At this point, destination is reached
        print("Press OK")
        i += 1
 
# Driver code
if __name__ == '__main__':
    str = "COZY"
 
    printPath(str)
 
# This code is contributed by
# Sanjit_Prasad

Time complexity: quadratic
Space complexity: constant
# Python program to check whether second string
# can be formed from first string
def canMakeStr2(s1, s2):
 
    # Create a count array and count
    # frequencies characters in s1
    count = {s1[i] : 0 for i in range(len(s1))}
     
    for i in range(len(s1)):
        count[s1[i]] += 1
     
    # Now traverse through str2 to check
    # if every character has enough counts
    for i in range(len(s2)):
        if (count.get(s2[i]) == None or count[s2[i]] == 0):
            return False
        count[s2[i]] -= 1
    return True
 
# Driver Code
s1 = "geekforgeeks"
s2 = "for"
 
if canMakeStr2(s1, s2):
    print("Yes")
else:
    print("No")

Time complexity: linear
Space complexity: constant
# python code to find the reverse
# alphabetical order from a given
# position
 
# Function which take the given string and the
# position from which the reversing shall be
# done and returns the modified string
def compute(st, n):
     
    # Creating a string having reversed
    # alphabetical order
    reverseAlphabet = "zyxwvutsrqponmlkjihgfedcba"
    l = len(st)
     
    # The string up to the point specified in the
    # question, the string remains unchanged and
    # from the point up to the length of the
    # string, we reverse the alphabetical order
    answer = ""
    for i in range(0, n):
        answer = answer + st[i];
             
    for i in range(n, l):
        answer = (answer +
        reverseAlphabet[ord(st[i]) - ord('a')]);
         
    return answer;
 
# Driver function
st = "pneumonia"
n = 4
answer = compute(st, n - 1)
print(answer)
 
# This code is contributed by Sam007.

Time complexity: linear
Space complexity: constant