#242 Valid Anagram

EasyArrays & Hashing~10 min

Given two strings s and t, return true if t is an anagram of s. That is, if t can be formed by rearranging the letters of s, using every letter exactly once, and false otherwise.

Examples

Inputs = "anagram", t = "nagaram"
Outputtrue

Both strings contain three a's, one n, one g, one r, one m.

Inputs = "rat", t = "car"
Outputfalse

The letter counts differ. There's no t in "car".

Constraints

  • 1 ≤ s.length, t.length ≤ 5 × 10⁴
  • s and t consist of lowercase English letters

The explainer is the good part.

Sign in for the full intuition build-up, every approach from naive to optimal with complexity analysis, progressive hints, and commented solutions in Python, JavaScript, and Java. All free.

Want a taste first? Try a free sample: Two Sum or Valid Parentheses.