Skip to main content
CodeOath
← All problems

Problem

Valid Anagram

Easy
  • strings
  • hash-table

Return true when s and t are made of the same letters, with each letter used the same number of times, possibly in a different order. Otherwise return false.

Example 1
Input
s = "stressed", t = "desserts"
Output
true
Explanation

both words use s three times, e twice, and t, r and d once each.

Example 2
Input
s = "aab", t = "abb"
Output
false
Explanation

both strings use only a and b, but s has two a and t has two b. The counts have to match, not just the letters.

Constraints:

  • 1 <= s.length, t.length <= 10^5
  • s and t contain only lowercase letters a to z
JavaScript

Tab indents. Press Esc, then Tab to leave the editor.

Run your code to see every test here. Nothing is submitted or recorded.