Problems › Hashing

Valid Anagram

Difficulty: Easy · Topic: Hashing

Given two strings s and t, return True if t is an anagram of s — i.e. it uses exactly the same letters with the same counts.

Examples

is_anagram("anagram", "nagaram")
→ true
is_anagram("rat", "car")
→ false
is_anagram("a", "a")
→ true

Target complexity: time O(n), space O(1)

Write your solution in Python and run it against hidden tests right on this page. Progressive hints and Python + C++ reference solutions are included.

Learn the idea first: the lesson for this problem.

More Hashing problems