Valid Anagram

Solution Code
class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        if len(s) != len(t):
            return False
        
        count = {}
        for char in s:
            count[char] = count.get(char, 0) + 1
            
        for char in t:
            if char not in count:
                return False
            count[char] -= 1
            if count[char] < 0:
                return False
                
        return True
Video GuideLeetcode Daily

Time Complexity

O(N)

Space Complexity

O(1)