Valid Anagram

Easy#242counting

You get two words, s and t. Find out whether the letters of s can be rearranged to make t. Our example: "secure" and "rescue" — yes, both have the same letters, two e's included.

input
s, t: strings.
returns
true if t is an anagram of s: the same letters, each as many times, in any order; otherwise false.
constraints
  • 1 ≤ s.length, t.length ≤ 2000
  • s, t: lowercase English letters
our 10 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
function isAnagram(s, t) {

}
Ctrl ↵
format
reset

saved in this browser

10 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more hash map problems

Pattern “Hash map” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.