Problem
You get two strings s and t. Return true if t is an anagram of s. Return false if it is not.
An anagram of a string contains the same characters the same number of times, maybe in a different order. For example, "night" and "thing" are anagrams.
Example 1
- Input:
- s = "notes", t = "stone"
- Output:
- true
- Explanation:
- Both strings contain one each of the letters
e,n,o,sandt.
Example 2
- Input:
- s = "cart", t = "trap"
- Output:
- false
- Explanation:
- The string
tcontains the letterp, butsdoes not.
Example 3
- Input:
- s = "aab", t = "abb"
- Output:
- false
- Explanation:
- Both strings use the letters
aandb, but the counts are different.
Constraints
- 1 <= s.length, t.length <= 5 * 10^4
- s and t contain only lowercase English letters.
Follow-up
Change your solution so that it also works when the strings contain any Unicode characters.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Accounts Merge
Coding · Array · Breadth-First Search · Depth-First Search
- Analyze User Website Visit Pattern
Coding · Array · Hash Table · Sorting
- Design In-Memory File System
Coding · Design · Hash Table · Sorting
- Group Anagrams
Coding · Array · Hash Table · Sorting
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 242. Valid Anagram
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 7 records
Amazon
Valid Anagram
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 61.7. This is not an interview probability.
View sourceGoogle
Valid Anagram
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 48.7. This is not an interview probability.
View sourceGoogle
Valid Anagram
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026