'''
keys: 
Solutions:
Similar: 
T:
S:
'''
from typing import List
from collections import Counter

# anagram: rearranging the letters of the word to make another

class Solution:
    # T: O(n); S: O(1) since the number of letters are fixed (26)
    # self-made
    def isAnagram(self, s: str, t: str) -> bool:
        return Counter(s) == Counter(t)
        
    
    # sample solutions
    def isAnagram1(self, s, t):
        dic1, dic2 = {}, {}
        for item in s:
            dic1[item] = dic1.get(item, 0) + 1
        for item in t:
            dic2[item] = dic2.get(item, 0) + 1
        return dic1 == dic2
    
    def isAnagram2(self, s, t):
        dic1, dic2 = [0]*26, [0]*26
        for item in s:
            dic1[ord(item)-ord('a')] += 1
        for item in t:
            dic2[ord(item)-ord('a')] += 1
        return dic1 == dic2
        
    # O(nlogn)
    def isAnagram3(self, s, t):
        return sorted(s) == sorted(t)
    
    def isAnagram4(self, s, t):
        dic = {}
        for i in s:
            if i not in dic:
                dic[i] = 1
            else:
                dic[i] += 1
        
        for j in t:
            if j not in dic:
                return False
            else:
                dic[j] -= 1
        
        for val in dic.values():
            if val != 0:
                return False
        
        return True




