---
# System prepended metadata

title: '[Valid Anagram](https://leetcode.com/problems/valid-anagram/)'
tags: [Leetcode, Easy, Arrays and Hashing]

---

# [Valid Anagram](https://leetcode.com/problems/valid-anagram/)
###### tags: `Leetcode`, `Easy`, `Arrays and Hashing`

## Approach
* Use a list of hashmap of size 26 and initialize it to have 0 by default.
* For **s**: *add* 1 to every count of letter corresponding to the index position of the list
* For **t**: *subtract* 1 to every count of letter corresponding to the index position of the list
* Iterate through every position of the list/hashmap and check is the value is 0. If any value is not 0, return False

## Asymptotic Analysis
### Time Complexity: **O(n)**
### Space Complexity: **O(1)** (Fixed value of 26 for list/map size for any value of n)

## Code
``` python
class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        frequencyList = [0] * 26
        for char in s:
            frequencyList[ord(char) - ord('a')] += 1
        for char in t:
            frequencyList[ord(char) - ord('a')] -= 1
        for freq in frequencyList:
            if freq != 0: return False
        return True
```