LC 242
LeetCode 242 · Easy

Valid Anagram

Given two strings, return true if one is an anagram of the other.

Hash map → · High frequency · Solve on LeetCode →

Try it

Step through the core mechanic. The simulator below runs the hash map shape this problem is built on.

Walk the pattern

No dedicated step-through for this one yet. The shape is Hash map — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.

The approach

Count characters of the first string in a 26-int array; decrement for the second. All-zero counts means an anagram. Length mismatch is an instant false.

AspectValue
PatternHash map
Recognise it bySame multiset of characters.
Time complexityO(n)
Space complexityO(1)
DifficultyEasy

Who asks it

Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.