AlgoLounge

Valid Anagram

easy

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

An anagram is a word formed by rearranging the letters of another word, using every original letter exactly once.

Examples

Example 1

Input:  s = "anagram", t = "nagaram"
Output: true

Example 2

Input:  s = "rat", t = "car"
Output: false

Constraints

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

Follow-up: what if the inputs contain arbitrary Unicode characters — does your solution still work?

TypeScript
Loading editor…
List of test cases (6)
Case 1
s = "anagram"
t = "nagaram"
Case 2
s = "rat"
t = "car"
Case 3
s = "a"
t = "a"
Case 4
s = "ab"
t = "a"
Case 5
s = "aacc"
t = "ccac"
Case 6
s = "listen"
t = "silent"