algorythms
Arrays & Hashing
LC #242Easy

Valid Anagram

Arrays & Hashing
AmazonGoogleMetaMicrosoft

Problem

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

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

Both have a×3, n×1, g×1, r×1, m×1

Hints — reveal one at a time