Menu
CoddyTech

Valid Anagram

Two strings are anagrams when one is a rearrangement of the other: they use the same letters, and each letter the same number of times. You get two strings s and t made of lowercase English letters. Return true if t is an anagram of s, and false otherwise.

Function

isAnagram(s: string, t: string) → boolean
sstring
the first string, lowercase letters
tstring
the string to test against s
Returnsboolean
true if t uses exactly the letters of s, each the same number of times

Constraints

  • 1 ≤ s.length, t.length ≤ 2 × 104
  • s and t contain only lowercase English letters (a to z).
  • The two lengths may differ.

Examples

Input
s = "listen"t = "silent"
Output
true
Explanation
Both words hold one e, i, l, n, s and t, so silent is listen with its letters moved around.

lock icon+19 hidden tests on Submit

challenge icon

Follow-up

What if the strings could hold any Unicode character instead of a to z? How would you change the counting?

Reset code
def isAnagram(s, t):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

s = "listen"
t = "silent"

Expected

true