Anagram Checker

Medium ⏱ 12 min 52% acceptance ★★★★★ 4.9
Write is_anagram(s1, s2) that returns True if s1 and s2 are anagrams of each other — the same letters, same counts — ignoring case and spaces entirely.

Examples

Example 1
Input
s1 = 'listen', s2 = 'silent'
Output
True
Explanation

Same letters rearranged.

Example 2
Input
s1 = 'Dormitory', s2 = 'Dirty Room'
Output
True
Explanation

Case and spaces are ignored before comparing.

Example 3
Input
s1 = 'hello', s2 = 'world'
Output
False
Explanation

Different letter counts.

Constraints

  • 0 <= len(s1), len(s2) <= 10^4

Topics

StringsAnagrams

Companies

GoogleMetaAmazon

Hints

Hint 1

Strip spaces and lowercase both strings first.

Hint 2

Two strings are anagrams if their sorted characters are equal.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.