15% off all plans & roadmaps Use code
See plansLeetCode 242 · Solution & editorial
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
Valid Anagram is a String Manipulation Patterns problem, in the Anagram Check (Frequency Count/Sort) subpattern. The pattern covers palindrome checking, anagram detection, pattern matching, and string conversion
Master anagram detection using frequency counting and sorting. Group anagrams efficiently.
The reference solution runs in O(n) time and O(1) space.
Valid Anagram has been reported in interviews at Bloomberg, Facebook, Microsoft, Amazon, Apple, Oracle, Google, Goldman Sachs.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Valid Anagram is a String Manipulation Patterns problem, in the Anagram Check (Frequency Count/Sort) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.