Valid Anagram

Arrays & Hashing, problem 2 of 9

Valid Anagram

Easy

LC #242

hash mapcountingstring

Not attempted yet

Given two strings s and t, return True if t is an anagram of s: it uses exactly the same letters, each the same number of times, in any order.

Example 1

Input: s = "listen", t = "silent"
Output: True

Example 2

Input: s = "rat", t = "car"
Output: False

Example 3

Input: s = "aab", t = "abb"
Output: False
Same letters, different counts.

Constraints

  • 1 ≤ len(s), len(t) ≤ 10^5
  • s and t contain lowercase English letters

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.