Arrays & Hashing
LC #242Easy
Valid Anagram
Arrays & Hashing
AmazonGoogleMetaMicrosoftProblem
Given two strings s and t, return true if t is an anagram of s — meaning they contain the exact same characters with the same frequencies (order doesn't matter). Example: s="anagram", t="nagaram" → true. s="rat", t="car" → false.
stringhash-mapsorting
Constraints
- ›1 ≤ s.length, t.length ≤ 5×10⁴
- ›s and t consist of lowercase English letters
Example
Input
s = "anagram", t = "nagaram"Output
trueWhy
Both have a×3, n×1, g×1, r×1, m×1