Given two strings, decide whether the second is an anagram of the first. Two strings qualify as anagrams when they have the same length and every character occurs the same number of times in both.
Return true when the second string is a rearrangement of the first, and false otherwise.
Example 1
Input: s = "listen", t = "silent"
Output: true
Both strings use the letters e, i, l, n, s, t exactly once, so one is a rearrangement of the other.
Example 2
Input: s = "hello", t = "world"
Output: false
The letter counts differ (for instance 'l' appears twice in "hello" but once in "world"), so they are not anagrams.
Constraints
1 <= s.length <= 5 * 10^41 <= t.length <= 5 * 10^4s and t consist of lowercase English lettersSee the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI