def anagram1(S1,S2):
    """ Checks if the two strings are anagram or not"""
    S1 = S1.replace(' ', '').lower()
    S2 = S2.replace(' ', '').lower()

    if len(S1) != len(S2): return False   # Edge case check

    count = {}
    for x in S1:
        if x in count:
            count[x] += 1
        else:
            count[x] = 1

    for x in S2:
        if x in count:
            count[x] -= 1
        else:
            count[x] = 1

    for i in count:
        if count[i] !=0:
            return False

    return True