<jupyter_start><jupyter_text>We are given a string S consisting of N characters and an integer K. The string represents a software license key which we would like to format. The string is composed of alphanumerical characters and/or dashes. The dashes split the alphanumerical characters within the string into groups (i.e. if there are M dashes, the string is split into M+1 groups). The dashes in the given string are possibly misplaced.We want each group of characters to be of length K (except for possibly the first group, which could be shorter, but still must contain at least one character). To satisfy this requirement, we will reinsert the dashes. Additionally, all the lower case letters in the string must be converted to upper case.For example, in the license key "2-4A0r7-4k" there are two dashes which split it into three groups of lengths 1, 5 and 2, respectively. If we want each group to be of length 4, then we would have to reinsert the dashes. Thus, for K = 4, the correctly formatted string is "24A0-R74K".Write a function:def solution(S, K)that, given a non-empty string S consisting of N characters, representing a license key to format, and an integer K, returns the license key formatted according to the description above.For example, given S = "2-4A0r7-4k" and K = 4, the function should return "24A0-R74K", and for K = 3, the function should return "24-A0R-74K" as the first group could be shorter. Given S = "r" and K = 1, the function should return "R".Write an efficient algorithm for the following assumptions:N and K are integers within the range [1..300,000];string S consists only of alphanumerical characters (a−z and/or A−Z and/or 0−9) and/or dashes (-);string S contains at least one alphanumerical character<jupyter_code>def solution(S, K):
    
    if len(S) == 1:
        return S.upper()
    else:
        
        splitted = S.split('-')
        len_split = [len(p) for p in splitted]

        if len(set(len_split[1:])) == 1:
            joined = "-".join(splitted)
            return joined.upper()
        else:
            just_string = "".join(splitted)
            d = [just_string[-K - i: len(just_string) - i] for i in range(0, len(just_string), K)]
            d = d[::-1]
            joined = "-".join(d)
            return joined.upper()

solution('2-4A0r7-4k', 3)
def solution(A):
    
    count = 0
    for i in range(1, len(A)):
        if i == len(A) - 1:
            count += 1
        else:
            a = [A[j] - A[i] for j in range(i + 1,len(A))]
            print(a)
#             jump = 0
#             for k in range(i, len(A)):
#                 if k < mval and mval > 0:
#                     mval = k
#             print(mval)
            b = a.index(min(a))
            print(b)
            c = [A[b + 1] - A[k] for k in range(b + 2, len(A))]
            print(c)
            
            if i == 1:
                break
            
    
    return
    
A = [10, 13, 12, 14, 15]
solution(A)
def solution(S, E):
    
    chairs = 0
    
    total_time = list(set(S + E))
    time_dict = dict.fromkeys(total_time,0)
    
    max_time = max(S)
    
    for i in range(len(total_time)):
        
        if i > max_time:
            continue
        else:
            if i in S:
                ind = S.index(i)
                time_dict[i] += 1
                if i != max_time:
                    E_key = E[ind]
                    time_dict[E_key] -= 1
                
    for i in time_dict.keys():
        if i <= max_time:
            chairs += time_dict[i]
            
    return chairs + 1

S = [1, 2, 6, 5, 3]
E = [5, 5, 7, 6, 8]
chairs = solution(S, E)
print(chairs)
#Problem ques: https://www.hackerrank.com/challenges/the-minion-game/problem
    
def minion_game(string):
    vowel_indices = list()
    consonant_indices = list()
    vowel_list = [vowel_indices.append(i) if a in 'AEIOU' else consonant_indices.append(i) for i,a in enumerate(string)]
    
    stuart_score = 0
    kevin_score = 0
    len_str = len(string)
    
    for i in consonant_indices:
        stuart_score += (len_str - i)
            
    for k in vowel_indices:
        kevin_score += (len_str - k)

    if stuart_score > kevin_score: 
        print("Stuart", stuart_score)
    elif kevin_score > stuart_score: 
        print("Kevin", kevin_score)
    else:
        print("Draw")
        
minion_game("BANANA")
# https://www.hackerrank.com/challenges/merge-the-tools/problem?h_r=next-challenge&h_v=zen

def merge_the_tools(string, k):
    
    
    pass

merge_the_tools('AABCAAADA',3)
a = "flamingo"
a[6:8]
print(sorted("silent"))
print(sorted("listen"))
class hello:
    
    def adding(a,b):
        return a + b
    
g = hello()
val = g.adding(5,4)
a = 'banana'
a[2:5]
5.0 / 4
4 / 1.0
lst = list()

def recur(x):
    
    if x == 0: 
        lst.append("Howdy!;")
    elif x % 2 == 0: 
        recur(x - 1)
    else: 
        lst.append(x)
        recur(x - 1)
        
recur(20)
print(lst)
class Animal:
    
    def __init__(self, action):
        self.action = action
        
    def perform(self):
        print(self.action)
    
    
class Dog(Animal):
    
    def __init__(self, action, name):
        super(action)
        self.name = name
    
    def intro(self):
        print("My name is " + self.name + "and I usually " + self.action)
    
a = Dog("sit", "Aldo")
a.intro()<jupyter_output><empty_output><jupyter_text>Karatsuba Algorithm<jupyter_code>def karatsuba(num1, num2):
    
    if len(str(num1)) == 1 or len(str(num2)) == 1:
        return num1 * num2
    else:
        factor = max(len(str(num1)), len(str(num2)))
        nby2 = int(factor / 2)
        
        a = int(num1 / 10 ** (nby2))
        b = num1 % 10 ** (nby2)
         
        c = int(num2 / 10 ** (nby2))
        d = num2 % 10 ** (nby2)
    
        ac = karatsuba(a, c)
        bd = karatsuba(b, d)
        ad_bc = karatsuba(a + b, c + d) - ac - bd
        prod = (10 ** (2 * nby2) * ac) + ((10 ** nby2) * ad_bc) + bd
        
        return prod
    
ans = karatsuba(1234, 5678)
print(ans)<jupyter_output>7006652<jupyter_text>Merge Sort Algorithm<jupyter_code>strings = '<NAME>'
sums = 0
for i in range(len(strings)):
    
    sums += (ord(strings[i]) * 31 ** (len(strings) - 1 - i)) % (10 ** 9 + 7)
    
print(sums)<jupyter_output>4837721833
{'fraction_non_alphanumeric': 0.11769377382465057, 'fraction_numerical': 0.028430749682337993, 'mean_word_length': 2.1065614208189443, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '540684', 'license': 'MIT', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2140, 'n_words': 674, 'path': 'practice/Sandbox.ipynb', 'repo_name': 'nikunjlad/Coding-Playground', 'size': '6304'}