← All problems

Valid Anagram

Easy stringshash maps LeetCode ↗
Given two strings s and t, determine whether t is an anagram of s — that is, whether t can be formed by rearranging exactly the letters of s. Both strings contain only lowercase English letters in the follow-up; solve the general case first.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(1) for fixed alphabet

Common pitfalls

  • Sorting is O(n log n) - fine but slower
  • Case sensitivity assumptions

Your solution

Log in to save your code and track progress.