Practice · Hashing · 1 of 7

Same Letters, Different Order

You are given two strings s and t of lowercase English letters.

Return true if t is an anagram of s: it uses exactly the same letters, each exactly as many times, possibly in a different order. Otherwise return false.

Example 1

Input
s = "listen", t = "silent"
Output
true
Both use e, i, l, n, s and t once each.

Example 2

Input
s = "aab", t = "abb"
Output
false
Both use only a and b, but s has two as and t has one.

Constraints

  • s and t each hold 1 to 5 × 10⁴ letters.
  • Both contain only the lowercase letters a to z.
Brush up firstHash Table visualiser