📚 PracticeEasyAlgorithm ProblemCoding Ready
Valid Anagram
hash-tablestringsorting
LeetCode #242
Updated Dec 20, 2025
Question
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
LeetCode: Valid Anagram
An anagram is a word formed by rearranging the letters of another word, using all original letters exactly once.
Example:
Input: s = "anagram", t = "nagaram"
Output: true
Input: s = "rat", t = "car"
Output: false
Hints
Hint 1
Two strings are anagrams if they have the same characters with the same frequencies. How can you count character frequencies?
Hint 2
Use a hash map to count characters in both strings, then compare the counts.
Hint 3
Alternatively, sorting both strings and comparing them also works. Which approach is more efficient?
Your Solution
python
Auto-saves every 30s
Try solving the problem first before viewing the solution
Learning Resources
Videos
Related Problems
0:00time spent