Valid Anagram

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

Example 1
Inputs = "anagram", t = "nagaram"
Outputtrue
t is an anagram of s because both strings contain the same characters with the same frequencies.
Example 2
Inputs = "rat", t = "car"
Outputfalse
t is not an anagram of s because the strings do not contain the same characters with the same frequencies.

Constraints

  • 1 <= s.length, t.length <= 5 * 10^4
  • s and t consist of lowercase English letters.

Asked at 38 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate