Valid Anagram
Easy · Arrays & Hashing · Hash Table · String · Counting
Problem
Given two strings s and t, return True if t is an anagram of s.
An anagram uses exactly the same letters with exactly the same multiplicities, in any order.
Examples
Input: s = "anagram", t = "nagaram" Output: True
Input: s = "rat", t = "car" Output: False
Constraints
- 1 <= len(s), len(t) <= 5 * 10^4
- s and t consist of lowercase English letters
Approaches
- Sort both strings — time O(n log n), space O(n)
Follow-up
How would you adapt your solution if the strings could contain arbitrary Unicode characters?
Related problems
Start free on Cariara · Coding problems · System design studio