iq.lab
Python starts when a code cell comes near or you run one
easyHash maps and sets target 15 min

Valid anagram

Two strings are anagrams when one is a rearrangement of the other: the same letters, each appearing the same number of times in both. You get two strings, s and t. Say whether they are anagrams of each other: return True or False.

Two empty strings count as anagrams of each other.

Example 1
Inputs = "stop", t = "pots"OutputTrue

Both have one s, one t, one o and one p.

Example 2
Inputs = "pool", t = "plop"OutputFalse

Same three letters, different counts: "pool" has two o's and one p, "plop" has one o and two p's.

Example 3
Inputs = "ten", t = "tent"OutputFalse

Strings of different lengths can never be anagrams.

Constraints
  • 0 ≤ len(s), len(t) ≤ 105

  • Both strings hold only the lowercase letters a to z.

Plan it first

Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.

⌘+Enter runs 0:00Python starts when a code cell comes near or you run one
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.