Hackerrank | Between Two Sets

def getTotalX(a, b):
    count = 0

    aValue = [];
    bValue = [];

    for i in range(1, 101):
        for k in range(len(a)):
            ans1 = i % a[k];
            if(ans1 == 0):
                aValue.append(i);
   
    aValue = remove_rep(aValue, len(a))
    #print(aValue)
    for i in range(1,101):
        for number in b:
            if number % i == 0:
                bValue.append(i);
    #print(aValue, bValue)
    bValue = remove_rep(bValue, len(b))
    
    aset = set(aValue)
    bset = set(bValue)

    common = aset.intersection(bset)
   
    for i in common:
        count += 1
    #print(count)
    return count
    

           
def remove_rep(arr, length):
    temp = []
    
    for i in range(0, len(arr)):

        if (arr.count(arr[i]) == length):
           temp.append(arr[i])
    return temp
                

Comments

Popular posts from this blog

Hackerrank | Sequence Equation

HackerRank | Organizing Containers of Balls

HackerRank | Minimum Distances